1  /-
  2  Copyright (c) 2020 Sébastien Gouëzel. All rights reserved.
  3  Released under Apache 2.0 license as described in the file LICENSE.
  4  Authors: Sébastien Gouëzel
  5  -/
  6  
  7  import geometry.manifold.basic_smooth_bundle
src         └───────────────────────────────────┘
  8  
  9  /-!
 10  # The derivative of functions between smooth manifolds
 11  
 12  Let `M` and `M'` be two smooth manifolds with corners over a field `𝕜` (with respective models with
 13  corners `I` on `(E, H)` and `I'` on `(E', H')`), and let `f : M → M'`. We define the
 14  derivative of the function at a point, within a set or along the whole space, mimicking the API
 15  for (Fréchet) derivatives. It is denoted by `mfderiv I I' f x`, where "m" stands for "manifold" and
 16  "f" for "Fréchet" (as in the usual derivative `fderiv 𝕜 f x`).
 17  
 18  ## Main definitions
 19  
 20  * `unique_mdiff_on I s` : predicate saying that, at each point of the set `s`, a function can have
 21    at most one derivative. This technical condition is important when we define
 22    `mfderiv_within` below, as otherwise there is an arbitrary choice in the derivative,
 23    and many properties will fail (for instance the chain rule). This is analogous to
 24    `unique_diff_on 𝕜 s` in a vector space.
 25  
 26  Let `f` be a map between smooth manifolds. The following definitions follow the `fderiv` API.
 27  
 28  * `mfderiv I I' f x` : the derivative of `f` at `x`, as a continuous linear map from the tangent
 29    space at `x` to the tangent space at `f x`. If the map is not differentiable, this is `0`.
 30  * `mfderiv_within I I' f s x` : the derivative of `f` at `x` within `s`, as a continuous linear map
 31    from the tangent space at `x` to the tangent space at `f x`. If the map is not differentiable
 32    within `s`, this is `0`.
 33  * `mdifferentiable_at I I' f x` : Prop expressing whether `f` is differentiable at `x`.
 34  * `mdifferentiable_within_at 𝕜 f s x` : Prop expressing whether `f` is differentiable within `s`
 35    at `x`.
 36  * `has_mfderiv_at I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative at `x`.
 37  * `has_mfderiv_within_at I I' f s x f'` : Prop expressing whether `f` has `f'` as a derivative
 38    within `s` at `x`.
 39  * `mdifferentiable_on I I' f s` : Prop expressing that `f` is differentiable on the set `s`.
 40  * `mdifferentiable I I' f` : Prop expressing that `f` is differentiable everywhere.
 41  * `bundle_mfderiv I I' f` : the derivative of `f`, as a map from the tangent bundle of `M` to the
 42    tangent bundle of `M'`.
 43  
 44  We also establish results on the differential of the identity, constant functions, charts, extended
 45  charts. For functions between vector spaces, we show that the usual notions and the manifold notions
 46  coincide.
 47  
 48  ## Implementation notes
 49  
 50  The tangent bundle is constructed using the machinery of topological fiber bundles, for which one
 51  can define bundled morphisms and construct canonically maps from the total space of one bundle to
 52  the total space of another one. One could use this mechanism to construct directly the derivative
 53  of a smooth map. However, we want to define the derivative of any map (and let it be zero if the map
 54  is not differentiable) to avoid proof arguments everywhere. This means we have to go back to the
 55  details of the definition of the total space of a fiber bundle constructed from core, to cook up a
 56  suitable definition of the derivative. It is the following: at each point, we have a preferred chart
 57  (used to identify the fiber above the point with the model vector space in fiber bundles). Then one
 58  should read the function using these preferred charts at `x` and `f x`, and take the derivative
 59  of `f` in these charts.
 60  
 61  Due to the fact that we are working in a model with corners, with an additional embedding `I` of the
 62  model space `H` in the model vector space `E`, the charts taking values in `E` are not the original
 63  charts of the manifold, but those ones composed with `I`, called extended charts. We
 64  define `written_in_ext_chart I I' x f` for the function `f` written in the preferred extended charts.
 65  Then the manifold derivative of `f`, at `x`, is just the usual derivative of
 66  `written_in_ext_chart I I' x f`, at the point `(ext_chart_at I x).to_fun x`.
 67  
 68  There is a subtelty with respect to continuity: if the function is not continuous, then the image
 69  of a small open set around `x` will not be contained in the source of the preferred chart around
 70  `f x`, which means that when reading `f` in the chart one is losing some information. To avoid this,
 71  we include continuity in the definition of differentiablity (which is reasonable since with any
 72  definition, differentiability implies continuity).
 73  
 74  *Warning*: the derivative (even within a subset) is a linear map on the whole tangent space. Suppose
 75  that one is given a smooth submanifold `N`, and a function which is smooth on `N` (i.e., its
 76  restriction to the subtype  `N` is smooth). Then, in the whole manifold `M`, the property
 77  `mdifferentiable_on I I' f N` holds. However, `mfderiv_within I I' f N` is not uniquely defined
 78  (what values would one choose for vectors that are transverse to `N`?), which can create issues down
 79  the road. The problem here is that knowing the value of `f` along `N` does not determine the
 80  differential of `f` in all directions. This is in contrast to the case where `N` would be an open
 81  subset, or a submanifold with boundary of maximal dimension, where this issue does not appear.
 82  The predicate `unique_mdiff_on I N` indicates that the derivative along `N` is unique if it exists,
 83  and is an assumption in most statements requiring a form of uniqueness.
 84  
 85  On a vector space, the manifold derivative and the usual derivative are equal. This means in
 86  particular that they live on the same space, i.e., the tangent space is defeq to the original vector
 87  space. To get this property is a motivation for our definition of the tangent space as a single
 88  copy of the vector space, instead of more usual definitions such as the space of derivations, or
 89  the space of equivalence classes of smooth curves in the manifold.
 90  
 91  ## Notations
 92  
 93  For the composition of local homeomorphisms and local equivs, we use respectively ` ≫ₕ` and ` ≫`.
 94  
 95  ## Tags
 96  Derivative, manifold
 97  -/
 98  
 99  noncomputable theory
100  open_locale classical topological_space
101  
102  open set
103  
104  local infixr  ` ≫ₕ `:100 := local_homeomorph.trans
id                               └────────────────────┘
src                              └────────────────────┘
typ                              └────────────────────┘
doc                              └────────────────────┘
105  local infixr  ` ≫ `:100 := local_equiv.trans
id                              └───────────────┘
src                             └───────────────┘
typ                             └───────────────┘
doc                             └───────────────┘
106  
107  universe u
108  
109  section derivatives_definitions
110  /-!
111  ### Derivative of maps between manifolds
112  
113  The derivative of a smooth map `f` between smooth manifold `M` and `M'` at `x` is a bounded linear
114  map from the tangent space to `M` at `x`, to the tangent space to `M'` at `f x`. Since we defined
115  the tangent space using one specific chart, the formula for the derivative is written in terms of
116  this specific chart.
117  
118  We use the names `mdifferentiable` and `mfderiv`, where the prefix letter `m` means "manifold".
119  -/
120  
121  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                          └──────────────────────┘
src                         └──────────────────────┘
typ                         └──────────────────────┘
doc                         └──────────────────────┘
122  {E : Type*} [normed_group E] [normed_space 𝕜 E]
id                └──────────┘     └──────────┘
src               └──────────┘     └──────────┘
typ               └──────────┘     └──────────┘
doc               └──────────┘     └──────────┘
123  {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
id                └───────────────┘         └────────────────┘
src               └───────────────┘         └────────────────┘
typ               └───────────────┘         └────────────────┘
doc               └───────────────┘         └────────────────┘
124  {M : Type*} [topological_space M] [manifold H M]
id                └───────────────┘     └──────┘
src               └───────────────┘     └──────┘
typ               └───────────────┘     └──────┘
doc               └───────────────┘     └──────┘
125  {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
id                 └──────────┘      └──────────┘
src                └──────────┘      └──────────┘
typ                └──────────┘      └──────────┘
doc                └──────────┘      └──────────┘
126  {H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H')
id                 └───────────────┘           └────────────────┘
src                └───────────────┘           └────────────────┘
typ                └───────────────┘           └────────────────┘
doc                └───────────────┘           └────────────────┘
127  {M' : Type*} [topological_space M'] [manifold H' M']
id                 └───────────────┘      └──────┘
src                └───────────────┘      └──────┘
typ                └───────────────┘      └──────┘
doc                └───────────────┘      └──────┘
128  
129  /-- Predicate ensuring that, at a point and within a set, a function can have at most one
130  derivative. This is expressed using the preferred chart at the considered point. -/
131  def unique_mdiff_within_at (s : set M) (x : M) :=
id                                   └─┘        
src                                  └─┘
typ                                  └─┘        
132  unique_diff_within_at 𝕜 ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun)
id   └───────────────────┘    └──────────┘   └─────┘  └─┘   └───┘ └─────┘
src  └───────────────────┘     └──────────┘     └─────┘  └─┘    └───┘  └─────┘
typ  └───────────────────┘    └──────────┘   └─────┘  └─┘   └───┘ └─────┘
doc  └───────────────────┘     └──────────┘              └─┘     └───┘
133    ((ext_chart_at I x).to_fun x)
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
134  
135  /-- Predicate ensuring that, at all points of a set, a function can have at most one derivative. -/
136  def unique_mdiff_on (s : set M) :=
id                            └─┘ 
src                           └─┘
typ                           └─┘ 
137  ∀x∈s, unique_mdiff_within_at I s x
id       └────────────────────┘   
src       └────────────────────┘
typ      └────────────────────┘   
doc        └────────────────────┘
138  
139  /-- Conjugating a function to write it in the preferred charts around `x`. The manifold derivative
140  of `f` will just be the derivative of this conjugated function. -/
141  def written_in_ext_chart_at (x : M) (f : M → M') : E → E' :=
id                                              └┘       └┘
typ                                             └┘       └┘
142  (ext_chart_at I' (f x)).to_fun ∘ f ∘ (ext_chart_at I x).inv_fun
id    └──────────┘ └┘     └────┘      └──────────┘   └─────┘
src   └──────────┘          └────┘       └──────────┘     └─────┘
typ   └──────────┘ └┘     └────┘      └──────────┘   └─────┘
doc   └──────────┘                         └──────────┘
143  
144  /-- `mdifferentiable_within_at I I' f s x` indicates that the function `f` between manifolds
145  has a derivative at the point `x` within the set `s`.
146  This is a generalization of `differentiable_within_at` to manifolds.
147  
148  We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by
149  `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
150  and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
151  this would not mean anything relevant. -/
152  def mdifferentiable_within_at (f : M → M') (s : set M) (x : M) :=
id                                         └┘       └─┘        
src                                                  └─┘
typ                                        └┘       └─┘        
153  continuous_within_at f s x ∧
id   └──────────────────┘    
src  └──────────────────┘       
typ  └──────────────────┘    
doc  └──────────────────┘
154  differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f)
id   └──────────────────────┘   └─────────────────────┘  └┘  
src  └──────────────────────┘    └─────────────────────┘
typ  └──────────────────────┘   └─────────────────────┘  └┘  
doc  └──────────────────────┘    └─────────────────────┘
155    ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun) ((ext_chart_at I x).to_fun x)
id       └──────────┘   └─────┘  └─┘   └───┘ └─────┘    └──────────┘   └────┘  
src      └──────────┘     └─────┘  └─┘    └───┘  └─────┘    └──────────┘     └────┘
typ      └──────────┘   └─────┘  └─┘   └───┘ └─────┘    └──────────┘   └────┘  
doc      └──────────┘              └─┘     └───┘             └──────────┘
156  
157  /-- `mdifferentiable_at I I' f x` indicates that the function `f` between manifolds
158  has a derivative at the point `x`.
159  This is a generalization of `differentiable_at` to manifolds.
160  
161  We require continuity in the definition, as otherwise points close to `x` could be sent by
162  `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
163  and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
164  this would not mean anything relevant. -/
165  def mdifferentiable_at (f : M → M') (x : M) :=
id                                  └┘       
typ                                 └┘       
166  continuous_at f x ∧
id   └───────────┘   
src  └───────────┘     
typ  └───────────┘   
doc  └───────────┘
167  differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f) (range I.to_fun)
id   └──────────────────────┘   └─────────────────────┘  └┘     └───┘ └─────┘
src  └──────────────────────┘    └─────────────────────┘            └───┘  └─────┘
typ  └──────────────────────┘   └─────────────────────┘  └┘     └───┘ └─────┘
doc  └──────────────────────┘    └─────────────────────┘            └───┘
168    ((ext_chart_at I x).to_fun x)
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
169  
170  /-- `mdifferentiable_on I I' f s` indicates that the function `f` between manifolds
171  has a derivative within `s` at all points of `s`.
172  This is a generalization of `differentiable_on` to manifolds. -/
173  def mdifferentiable_on (f : M → M') (s : set M) :=
id                                  └┘       └─┘ 
src                                           └─┘
typ                                 └┘       └─┘ 
174  ∀x ∈ s, mdifferentiable_within_at I I' f s x
id         └───────────────────────┘  └┘   
src          └───────────────────────┘
typ        └───────────────────────┘  └┘   
doc          └───────────────────────┘
175  
176  /-- `mdifferentiable I I' f` indicates that the function `f` between manifolds
177  has a derivative everywhere.
178  This is a generalization of `differentiable` to manifolds. -/
179  def mdifferentiable (f : M → M') :=
id                               └┘
typ                              └┘
180  ∀x, mdifferentiable_at I I' f x
id      └────────────────┘  └┘  
src      └────────────────┘
typ     └────────────────┘  └┘  
doc      └────────────────┘
181  
182  /-- Prop registering if a local homeomorphism is a local diffeomorphism on its source -/
183  def local_homeomorph.mdifferentiable (f : local_homeomorph M M') :=
id                                             └──────────────┘  └┘
src                                            └──────────────┘
typ                                            └──────────────┘  └┘
doc                                            └──────────────┘
184  (mdifferentiable_on I I' f.to_fun f.source) ∧ (mdifferentiable_on I' I f.inv_fun f.target)
id    └────────────────┘  └┘ └─────┘ └─────┘    └────────────────┘ └┘  └──────┘ └─────┘
src   └────────────────┘       └─────┘  └─────┘    └────────────────┘       └──────┘  └─────┘
typ   └────────────────┘  └┘ └─────┘ └─────┘    └────────────────┘ └┘  └──────┘ └─────┘
doc   └────────────────┘                            └────────────────┘
185  
186  variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners I' M']
id              └──────────────────────────┘       └──────────────────────────┘
src             └──────────────────────────┘       └──────────────────────────┘
typ             └──────────────────────────┘       └──────────────────────────┘
doc             └──────────────────────────┘       └──────────────────────────┘
187  
188  /-- `has_mfderiv_within_at I I' f s x f'` indicates that the function `f` between manifolds
189  has, at the point `x` and within the set `s`, the derivative `f'`. Here, `f'` is a continuous linear
190  map from the tangent space at `x` to the tangent space at `f x`.
191  
192  This is a generalization of `has_fderiv_within_at` to manifolds (as indicated by the prefix `m`).
193  The order of arguments is changed as the type of the derivative `f'` depends on the choice of `x`.
194  
195  We require continuity in the definition, as otherwise points close to `x` in `s` could be sent by
196  `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
197  and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
198  this would not mean anything relevant. -/
199  def has_mfderiv_within_at (f : M → M') (s : set M) (x : M)
id                                     └┘       └─┘        
src                                              └─┘
typ                                    └┘       └─┘        
200    (f' : tangent_space I x →L[𝕜] tangent_space I' (f x)) :=
id           └───────────┘   └─┘ └───────────┘ └┘   
src          └───────────┘     └─┘  └───────────┘
typ          └───────────┘   └─┘ └───────────┘ └┘   
doc          └───────────┘     └─┘  └───────────┘
201  continuous_within_at f s x ∧
id   └──────────────────┘    
src  └──────────────────┘       
typ  └──────────────────┘    
doc  └──────────────────┘
202  has_fderiv_within_at (written_in_ext_chart_at I I' x f : E → E') f'
id   └──────────────────┘  └─────────────────────┘  └┘        └┘  └┘
src  └──────────────────┘  └─────────────────────┘
typ  └──────────────────┘  └─────────────────────┘  └┘        └┘  └┘
doc  └──────────────────┘  └─────────────────────┘
203    ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun) ((ext_chart_at I x).to_fun x)
id       └──────────┘   └─────┘  └─┘   └───┘ └─────┘    └──────────┘   └────┘  
src      └──────────┘     └─────┘  └─┘    └───┘  └─────┘    └──────────┘     └────┘
typ      └──────────┘   └─────┘  └─┘   └───┘ └─────┘    └──────────┘   └────┘  
doc      └──────────┘              └─┘     └───┘             └──────────┘
204  
205  /-- `has_mfderiv_at I I' f x f'` indicates that the function `f` between manifolds
206  has, at the point `x`, the derivative `f'`. Here, `f'` is a continuous linear
207  map from the tangent space at `x` to the tangent space at `f x`.
208  
209  We require continuity in the definition, as otherwise points close to `x` `s` could be sent by
210  `f` outside of the chart domain around `f x`. Then the chart could do anything to the image points,
211  and in particular by coincidence `written_in_ext_chart_at I I' x f` could be differentiable, while
212  this would not mean anything relevant. -/
213  def has_mfderiv_at (f : M → M') (x : M)
id                              └┘       
typ                             └┘       
214    (f' : tangent_space I x →L[𝕜] tangent_space I' (f x)) :=
id           └───────────┘   └─┘ └───────────┘ └┘   
src          └───────────┘     └─┘  └───────────┘
typ          └───────────┘   └─┘ └───────────┘ └┘   
doc          └───────────┘     └─┘  └───────────┘
215  continuous_at f x ∧
id   └───────────┘   
src  └───────────┘     
typ  └───────────┘   
doc  └───────────┘
216  has_fderiv_within_at (written_in_ext_chart_at I I' x f : E → E') f' (range I.to_fun)
id   └──────────────────┘  └─────────────────────┘  └┘        └┘  └┘  └───┘ └─────┘
src  └──────────────────┘  └─────────────────────┘                        └───┘  └─────┘
typ  └──────────────────┘  └─────────────────────┘  └┘        └┘  └┘  └───┘ └─────┘
doc  └──────────────────┘  └─────────────────────┘                        └───┘
217    ((ext_chart_at I x).to_fun x)
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
218  
219  /-- Let `f` be a function between two smooth manifolds. Then `mfderiv_within I I' f s x` is the
220  derivative of `f` at `x` within `s`, as a continuous linear map from the tangent space at `x` to the
221  tangent space at `f x`. -/
222  def mfderiv_within (f : M → M') (s : set M) (x : M) : tangent_space I x →L[𝕜] tangent_space I' (f x) :=
id                              └┘       └─┘            └───────────┘   └─┘ └───────────┘ └┘   
src                                       └─┘              └───────────┘     └─┘  └───────────┘
typ                             └┘       └─┘            └───────────┘   └─┘ └───────────┘ └┘   
doc                                                        └───────────┘     └─┘  └───────────┘
223  if h : mdifferentiable_within_at I I' f s x then
id   └┘     └───────────────────────┘  └┘   
src  └┘     └───────────────────────┘
typ  └┘     └───────────────────────┘  └┘   
doc         └───────────────────────┘
224  (fderiv_within 𝕜 (written_in_ext_chart_at I I' x f) ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun)
id    └───────────┘   └─────────────────────┘  └┘      └──────────┘   └─────┘  └─┘   └───┘ └─────┘
src   └───────────┘    └─────────────────────┘             └──────────┘     └─────┘  └─┘    └───┘  └─────┘
typ   └───────────┘   └─────────────────────┘  └┘      └──────────┘   └─────┘  └─┘   └───┘ └─────┘
doc   └───────────┘    └─────────────────────┘             └──────────┘              └─┘     └───┘
225    ((ext_chart_at I x).to_fun x) : _)
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
226  else continuous_linear_map.zero
id        └────────────────────────┘
src       └────────────────────────┘
typ       └────────────────────────┘
doc       └────────────────────────┘
227  
228  /-- Let `f` be a function between two smooth manifolds. Then `mfderiv I I' f x` is the derivative of
229  `f` at `x`, as a continuous linear map from the tangent space at `x` to the tangent space at `f x`. -/
230  def mfderiv (f : M → M') (x : M) : tangent_space I x →L[𝕜] tangent_space I' (f x) :=
id                       └┘           └───────────┘   └─┘ └───────────┘ └┘   
src                                     └───────────┘     └─┘  └───────────┘
typ                      └┘           └───────────┘   └─┘ └───────────┘ └┘   
doc                                     └───────────┘     └─┘  └───────────┘
231  if h : mdifferentiable_at I I' f x then
id   └┘     └────────────────┘  └┘  
src  └┘     └────────────────┘
typ  └┘     └────────────────┘  └┘  
doc         └────────────────┘
232  (fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : E → E') (range I.to_fun)
id    └───────────┘   └─────────────────────┘  └┘        └┘   └───┘ └─────┘
src   └───────────┘    └─────────────────────┘                     └───┘  └─────┘
typ   └───────────┘   └─────────────────────┘  └┘        └┘   └───┘ └─────┘
doc   └───────────┘    └─────────────────────┘                     └───┘
233    ((ext_chart_at I x).to_fun x) : _)
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
234  else continuous_linear_map.zero
id        └────────────────────────┘
src       └────────────────────────┘
typ       └────────────────────────┘
doc       └────────────────────────┘
235  
236  set_option class.instance_max_depth 60
doc             └──────────────────────┘
237  
238  /-- The derivative within a set, as a map between the tangent bundles -/
239  def bundle_mfderiv_within (f : M → M') (s : set M) : tangent_bundle I M → tangent_bundle I' M' :=
id                                     └┘       └─┘     └────────────┘     └────────────┘ └┘ └┘
src                                              └─┘      └────────────┘       └────────────┘
typ                                    └┘       └─┘     └────────────┘     └────────────┘ └┘ └┘
doc                                                       └────────────┘       └────────────┘
240  λp, ⟨f p.1, (mfderiv_within I I' f s p.1 : tangent_space I p.1 → tangent_space I' (f p.1)) p.2⟩
id            └────────────┘  └┘       └───────────┘      └───────────┘ └┘       
src              └────────────┘               └───────────┘        └───────────┘             
typ           └────────────┘  └┘       └───────────┘      └───────────┘ └┘       
doc               └────────────┘                └───────────┘         └───────────┘
241  
242  /-- The derivative, as a map between the tangent bundles -/
243  def bundle_mfderiv (f : M → M') : tangent_bundle I M → tangent_bundle I' M' :=
id                              └┘    └────────────┘     └────────────┘ └┘ └┘
src                                    └────────────┘       └────────────┘
typ                             └┘    └────────────┘     └────────────┘ └┘ └┘
doc                                    └────────────┘       └────────────┘
244  λp, ⟨f p.1, (mfderiv I I' f p.1 : tangent_space I p.1 → tangent_space I' (f p.1)) p.2⟩
id            └─────┘  └┘      └───────────┘      └───────────┘ └┘       
src              └─────┘             └───────────┘        └───────────┘             
typ           └─────┘  └┘      └───────────┘      └───────────┘ └┘       
doc               └─────┘              └───────────┘         └───────────┘
245  
246  end derivatives_definitions
247  
248  section derivatives_properties
249  /-! ### Unique differentiability sets in manifolds -/
250  
251  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                          └──────────────────────┘
src                         └──────────────────────┘
typ                         └──────────────────────┘
doc                         └──────────────────────┘
252  {E : Type*} [normed_group E] [normed_space 𝕜 E]
id                └──────────┘     └──────────┘
src               └──────────┘     └──────────┘
typ               └──────────┘     └──────────┘
doc               └──────────┘     └──────────┘
253  {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
id                └───────────────┘         └────────────────┘
src               └───────────────┘         └────────────────┘
typ               └───────────────┘         └────────────────┘
doc               └───────────────┘         └────────────────┘
254  {M : Type*} [topological_space M] [manifold H M] --
id                └───────────────┘     └──────┘
src               └───────────────┘     └──────┘
typ               └───────────────┘     └──────┘
doc               └───────────────┘     └──────┘
255  {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
id                 └──────────┘      └──────────┘
src                └──────────┘      └──────────┘
typ                └──────────┘      └──────────┘
doc                └──────────┘      └──────────┘
256  {H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
id                 └───────────────┘           └────────────────┘
src                └───────────────┘           └────────────────┘
typ                └───────────────┘           └────────────────┘
doc                └───────────────┘           └────────────────┘
257  {M' : Type*} [topological_space M'] [manifold H' M']
id                 └───────────────┘      └──────┘
src                └───────────────┘      └──────┘
typ                └───────────────┘      └──────┘
doc                └───────────────┘      └──────┘
258  {E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
id                  └──────────┘       └──────────┘
src                 └──────────┘       └──────────┘
typ                 └──────────┘       └──────────┘
doc                 └──────────┘       └──────────┘
259  {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
id                  └───────────────┘             └────────────────┘
src                 └───────────────┘             └────────────────┘
typ                 └───────────────┘             └────────────────┘
doc                 └───────────────┘             └────────────────┘
260  {M'' : Type*} [topological_space M''] [manifold H'' M'']
id                  └───────────────┘       └──────┘
src                 └───────────────┘       └──────┘
typ                 └───────────────┘       └──────┘
doc                 └───────────────┘       └──────┘
261  {f f₀ f₁ : M → M'}
262  {x : M}
263  {s t : set M}
id          └─┘
src         └─┘
typ         └─┘
264  {g : M' → M''}
265  {u : set M'}
id        └─┘
src       └─┘
typ       └─┘
266  
267  lemma unique_mdiff_within_at_univ : unique_mdiff_within_at I univ x :=
id                                       └────────────────────┘  └──┘ 
src                                      └────────────────────┘   └──┘
typ                                      └────────────────────┘  └──┘ 
doc                                      └────────────────────┘
268  begin
st   └─────
269    unfold unique_mdiff_within_at,
src    └───────────────────────────┘
typ    └───────────────────────────┘
doc    └───────────────────────────┘
txt    └───────────────────────────┘
par    └───────────────────────────┘
pid          └─────────────────────┘
st   ──────────────────────────────┘└─
270    simp only [preimage_univ, univ_inter],
id                └───────────┘  └────────┘
src    └─────────┘└───────────┘└┘└────────┘
typ    └─────────┘└───────────┘└┘└────────┘
doc    └─────────┘             └┘          
txt    └─────────┘             └┘          
par    └─────────┘             └┘          
pid        └──┘└┘             └┘          
st   ──────────────────────────────────────┘└─
271    exact I.unique_diff _ (mem_range_self _)
id           └───────────┘    └────────────┘
src    └────┘└───────────┘└─┘ └────────────┘└──┘
typ    └────┘└───────────┘└─┘ └────────────┘└──┘
doc    └────┘             └─┘               └──┘
txt    └────┘             └─┘               └──┘
par    └────┘             └─┘               └──┘
pid                      └─┘               └─┘
st   ──────────────────────────────────────────┘
272  end
st   └─┘
273  variable {I}
274  
275  lemma unique_mdiff_within_at_iff {s : set M} {x : M} :
id                                         └─┘        
src                                        └─┘
typ                                        └─┘        
276    unique_mdiff_within_at I s x ↔
id     └────────────────────┘    
src    └────────────────────┘       
typ    └────────────────────┘    
doc    └────────────────────┘
277    unique_diff_within_at 𝕜 ((ext_chart_at I x).inv_fun ⁻¹' s ∩ (ext_chart_at I x).target)
id     └───────────────────┘    └──────────┘   └─────┘  └─┘    └──────────┘   └────┘
src    └───────────────────┘     └──────────┘     └─────┘  └─┘     └──────────┘     └────┘
typ    └───────────────────┘    └──────────┘   └─────┘  └─┘    └──────────┘   └────┘
doc    └───────────────────┘     └──────────┘              └─┘      └──────────┘
278    ((ext_chart_at I x).to_fun x) :=
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
279  begin
st   └─────
280    apply unique_diff_within_at_congr,
id           └─────────────────────────┘
src    └────┘└─────────────────────────┘
typ    └────┘└─────────────────────────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ──────────────────────────────────┘└─
281    rw [nhds_within_inter, nhds_within_inter, nhds_within_ext_chart_target_eq]
id         └───────────────┘  └───────────────┘  └─────────────────────────────┘
src    └──┘└───────────────┘└┘└───────────────┘└┘└─────────────────────────────┘└┘
typ    └──┘└───────────────┘└┘└───────────────┘└┘└─────────────────────────────┘└┘
doc    └──┘                 └┘                 └┘                               └┘
txt    └──┘                 └┘                 └┘                               └┘
par    └──┘                 └┘                 └┘                               └┘
pid      └┘                 └┘                 └┘                               
st   ──────────────────────┘└─────────────────┘└───────────────────────────────┘
282  end
st   └─┘
283  
284  lemma unique_mdiff_within_at.mono (h : unique_mdiff_within_at I s x) (st : s ⊆ t) :
id                                          └────────────────────┘             
src                                         └────────────────────┘                
typ                                         └────────────────────┘             
doc                                         └────────────────────┘
285    unique_mdiff_within_at I t x :=
id     └────────────────────┘   
src    └────────────────────┘
typ    └────────────────────┘   
doc    └────────────────────┘
286  unique_diff_within_at.mono h $ inter_subset_inter (preimage_mono st) (subset.refl _)
id   └────────────────────────┘    └────────────────┘  └───────────┘ └┘   └─────────┘
src  └────────────────────────┘     └────────────────┘  └───────────┘      └─────────┘
typ  └────────────────────────┘    └────────────────┘  └───────────┘ └┘   └─────────┘
287  
288  lemma unique_mdiff_within_at.inter' (hs : unique_mdiff_within_at I s x) (ht : t ∈ nhds_within x s) :
id                                             └────────────────────┘             └─────────┘  
src                                            └────────────────────┘                 └─────────┘
typ                                            └────────────────────┘             └─────────┘  
doc                                            └────────────────────┘                  └─────────┘
289    unique_mdiff_within_at I (s ∩ t) x :=
id     └────────────────────┘       
src    └────────────────────┘      
typ    └────────────────────┘       
doc    └────────────────────┘
290  begin
st   └─────
291    rw [unique_mdiff_within_at, ext_chart_preimage_inter_eq],
id         └────────────────────┘  └─────────────────────────┘
src    └──┘└────────────────────┘└┘└─────────────────────────┘
typ    └──┘└────────────────────┘└┘└─────────────────────────┘
doc    └──┘└────────────────────┘└┘└─────────────────────────┘
txt    └──┘                      └┘                           
par    └──┘                      └┘                           
pid      └┘                      └┘                           
st   ───────────────────────────┘└───────────────────────────┘└──
292    exact unique_diff_within_at.inter' hs (ext_chart_preimage_mem_nhds_within I x ht)
id           └──────────────────────────┘ └┘  └────────────────────────────────┘   └┘
src    └────┘└──────────────────────────┘   └────────────────────────────────┘    └┘
typ    └────┘└──────────────────────────┘└┘ └────────────────────────────────┘└┘└┘
doc    └────┘                               └────────────────────────────────┘    └┘
txt    └────┘                                                                     └┘
par    └────┘                                                                     └┘
pid                                                                              
st   ───────────────────────────────────────────────────────────────────────────────────┘
293  end
st   └─┘
294  
295  lemma unique_mdiff_within_at.inter (hs : unique_mdiff_within_at I s x) (ht : t ∈ 𝓝 x) :
id                                            └────────────────────┘              
src                                           └────────────────────┘                 
typ                                           └────────────────────┘              
doc                                           └────────────────────┘                  
296    unique_mdiff_within_at I (s ∩ t) x :=
id     └────────────────────┘       
src    └────────────────────┘      
typ    └────────────────────┘       
doc    └────────────────────┘
297  begin
st   └─────
298    rw [unique_mdiff_within_at, ext_chart_preimage_inter_eq],
id         └────────────────────┘  └─────────────────────────┘
src    └──┘└────────────────────┘└┘└─────────────────────────┘
typ    └──┘└────────────────────┘└┘└─────────────────────────┘
doc    └──┘└────────────────────┘└┘└─────────────────────────┘
txt    └──┘                      └┘                           
par    └──┘                      └┘                           
pid      └┘                      └┘                           
st   ───────────────────────────┘└───────────────────────────┘└──
299    exact unique_diff_within_at.inter hs (ext_chart_preimage_mem_nhds I x ht)
id           └─────────────────────────┘ └┘  └─────────────────────────┘   └┘
src    └────┘└─────────────────────────┘   └─────────────────────────┘    └┘
typ    └────┘└─────────────────────────┘└┘ └─────────────────────────┘└┘└┘
doc    └────┘                              └─────────────────────────┘    └┘
txt    └────┘                                                             └┘
par    └────┘                                                             └┘
pid                                                                      
st   ───────────────────────────────────────────────────────────────────────────┘
300  end
st   └─┘
301  
302  lemma is_open.unique_mdiff_within_at (xs : x ∈ s) (hs : is_open s) : unique_mdiff_within_at I s x :=
id                                                        └─────┘     └────────────────────┘   
src                                                         └─────┘      └────────────────────┘
typ                                                       └─────┘     └────────────────────┘   
doc                                                          └─────┘      └────────────────────┘
303  begin
st   └─────
304    have := unique_mdiff_within_at.inter (unique_mdiff_within_at_univ I) (mem_nhds_sets hs xs),
id             └──────────────────────────┘  └─────────────────────────┘    └───────────┘ └┘ └┘
src    └──────┘└──────────────────────────┘ └─────────────────────────┘ └┘ └───────────┘    
typ    └──────┘└──────────────────────────┘ └─────────────────────────┘└┘ └───────────┘└┘└┘
doc    └──────┘                                                         └┘                  
txt    └──────┘                                                         └┘                  
par    └──────┘                                                         └┘                  
pid    └───┘└─┘                                                         └┘                  
st   ───────────────────────────────────────────────────────────────────────────────────────────┘└─
305    rwa univ_inter at this
id         └────────┘
src    └──┘└────────┘└───────┘
typ    └──┘└────────┘└───────┘
doc    └──┘          └───────┘
txt    └──┘          └───────┘
par    └──┘          └───────┘
pid                 └──────┘
st   ────────────────────────┘
306  end
st   └─┘
307  
308  lemma unique_mdiff_on.inter (hs : unique_mdiff_on I s) (ht : is_open t) : unique_mdiff_on I (s ∩ t) :=
id                                     └─────────────┘          └─────┘     └─────────────┘     
src                                    └─────────────┘            └─────┘      └─────────────┘      
typ                                    └─────────────┘          └─────┘     └─────────────┘     
doc                                    └─────────────┘            └─────┘      └─────────────┘
309  λx hx, unique_mdiff_within_at.inter (hs _ hx.1) (mem_nhds_sets ht hx.2)
id     └┘  └──────────────────────────┘  └┘   └┘    └───────────┘ └┘ └┘
src         └──────────────────────────┘             └───────────┘      
typ    └┘  └──────────────────────────┘  └┘   └┘    └───────────┘ └┘ └┘
310  
311  lemma is_open.unique_mdiff_on (hs : is_open s) : unique_mdiff_on I s :=
id                                       └─────┘     └─────────────┘  
src                                      └─────┘      └─────────────┘
typ                                      └─────┘     └─────────────┘  
doc                                      └─────┘      └─────────────┘
312  λx hx, is_open.unique_mdiff_within_at hx hs
id     └┘  └────────────────────────────┘ └┘ └┘
src         └────────────────────────────┘
typ    └┘  └────────────────────────────┘ └┘ └┘
313  
314  /- We name the typeclass variables related to `smooth_manifold_with_corners` structure as they are
315  necessary in lemmas mentioning the derivative, but not in lemmas about differentiability, so we
316  want to include them or omit them when necessary. -/
317  variables [Is : smooth_manifold_with_corners I M] [I's : smooth_manifold_with_corners I' M']
id                   └──────────────────────────┘             └──────────────────────────┘
src                  └──────────────────────────┘             └──────────────────────────┘
typ                  └──────────────────────────┘             └──────────────────────────┘
doc                  └──────────────────────────┘             └──────────────────────────┘
318  [I''s : smooth_manifold_with_corners I'' M'']
id           └──────────────────────────┘
src          └──────────────────────────┘
typ          └──────────────────────────┘
doc          └──────────────────────────┘
319  {f' f₀' f₁' : tangent_space I x →L[𝕜] tangent_space I' (f x)}
id                 └───────────┘     └─┘  └───────────┘
src                └───────────┘     └─┘  └───────────┘
typ                └───────────┘     └─┘  └───────────┘
doc                └───────────┘     └─┘  └───────────┘
320  {g' : tangent_space I' (f x) →L[𝕜] tangent_space I'' (g (f x))}
id         └───────────┘          └─┘  └───────────┘
src        └───────────┘          └─┘  └───────────┘
typ        └───────────┘          └─┘  └───────────┘
doc        └───────────┘          └─┘  └───────────┘
321  
322  /-- `unique_mdiff_within_at` achieves its goal: it implies the uniqueness of the derivative. -/
323  theorem unique_mdiff_within_at.eq (U : unique_mdiff_within_at I s x)
id                                          └────────────────────┘   
src                                         └────────────────────┘
typ                                         └────────────────────┘   
doc                                         └────────────────────┘
324    (h : has_mfderiv_within_at I I' f s x f') (h₁ : has_mfderiv_within_at I I' f s x f₁') : f' = f₁' :=
id          └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └─┘    └┘  └─┘
src         └───────────────────┘                      └───────────────────┘                      
typ         └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └─┘    └┘  └─┘
doc         └───────────────────┘                      └───────────────────┘
325  U.eq h.2 h₁.2
id   └─┘   └┘
src   └─┘      
typ  └─┘   └┘
doc   └─┘
326  
327  theorem unique_mdiff_on.eq (U : unique_mdiff_on I s) (hx : x ∈ s)
id                                   └─────────────┘            
src                                  └─────────────┘              
typ                                  └─────────────┘            
doc                                  └─────────────┘
328    (h : has_mfderiv_within_at I I' f s x f') (h₁ : has_mfderiv_within_at I I' f s x f₁') : f' = f₁' :=
id          └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └─┘    └┘  └─┘
src         └───────────────────┘                      └───────────────────┘                      
typ         └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └─┘    └┘  └─┘
doc         └───────────────────┘                      └───────────────────┘
329  unique_mdiff_within_at.eq (U _ hx) h h₁
id   └───────────────────────┘     └┘   └┘
src  └───────────────────────┘
typ  └───────────────────────┘     └┘   └┘
doc  └───────────────────────┘
330  
331  
332  /-!
333  ### General lemmas on derivatives of functions between manifolds
334  
335  We mimick the API for functions between vector spaces
336  -/
337  
338  lemma mdifferentiable_within_at_iff {f : M → M'} {s : set M} {x : M} :
id                                               └┘       └─┘        
src                                                        └─┘
typ                                              └┘       └─┘        
339    mdifferentiable_within_at I I' f s x ↔
id     └───────────────────────┘  └┘    
src    └───────────────────────┘            
typ    └───────────────────────┘  └┘    
doc    └───────────────────────┘
340    continuous_within_at f s x ∧
id     └──────────────────┘    
src    └──────────────────┘       
typ    └──────────────────┘    
doc    └──────────────────┘
341    differentiable_within_at 𝕜 (written_in_ext_chart_at I I' x f)
id     └──────────────────────┘   └─────────────────────┘  └┘  
src    └──────────────────────┘    └─────────────────────┘
typ    └──────────────────────┘   └─────────────────────┘  └┘  
doc    └──────────────────────┘    └─────────────────────┘
342      ((ext_chart_at I x).target ∩ (ext_chart_at I x).inv_fun ⁻¹' s) ((ext_chart_at I x).to_fun x) :=
id         └──────────┘   └────┘    └──────────┘   └─────┘  └─┘     └──────────┘   └────┘  
src        └──────────┘     └────┘    └──────────┘     └─────┘  └─┘      └──────────┘     └────┘
typ        └──────────┘   └────┘    └──────────┘   └─────┘  └─┘     └──────────┘   └────┘  
doc        └──────────┘                └──────────┘              └─┘      └──────────┘
343  begin
st   └─────
344    refine and_congr iff.rfl (exists_congr $ λ f', _),
id            └───────┘ └─────┘  └──────────┘
src    └─────┘└───────┘└─────┘ └──────────┘  └─────┘
typ    └─────┘└───────┘└─────┘ └──────────┘  └─────┘
doc    └─────┘                               └─────┘
txt    └─────┘                               └─────┘
par    └─────┘                               └─────┘
pid                                         └─────┘
st   ──────────────────────────────────────────────────┘└─
345    rw [inter_comm],
id         └────────┘
src    └──┘└────────┘
typ    └──┘└────────┘
doc    └──┘          
txt    └──┘          
par    └──┘          
pid      └┘          
st   ───────────────┘└──
346    simp only [has_fderiv_within_at, nhds_within_inter, nhds_within_ext_chart_target_eq]
id                └──────────────────┘  └───────────────┘  └─────────────────────────────┘
src    └─────────┘└──────────────────┘└┘└───────────────┘└┘└─────────────────────────────┘└┘
typ    └─────────┘└──────────────────┘└┘└───────────────┘└┘└─────────────────────────────┘└┘
doc    └─────────┘└──────────────────┘└┘                 └┘                               └┘
txt    └─────────┘                    └┘                 └┘                               └┘
par    └─────────┘                    └┘                 └┘                               └┘
pid        └──┘└┘                    └┘                 └┘                               
st   ──────────────────────────────────────────────────────────────────────────────────────┘
347  end
st   └─┘
348  
349  include Is I's
350  set_option class.instance_max_depth 60
doc             └──────────────────────┘
351  
352  lemma mfderiv_within_zero_of_not_mdifferentiable_within_at
353    (h : ¬ mdifferentiable_within_at I I' f s x) : mfderiv_within I I' f s x = 0 :=
id           └───────────────────────┘  └┘       └────────────┘  └┘    
src          └───────────────────────┘               └────────────┘            
typ          └───────────────────────┘  └┘       └────────────┘  └┘    
doc           └───────────────────────┘               └────────────┘
354  by { simp [mfderiv_within, h], refl }
id              └────────────┘  
src       └────┘└────────────┘└┘   └───┘
typ       └────┘└────────────┘└┘  └───┘
doc       └────┘└────────────┘└┘   └───┘
txt       └────┘              └┘   └───┘
par       └────┘              └┘   └───┘
pid                         └┘       
st     └─────────────────────────┘└─────┘└┘
355  
356  lemma mfderiv_zero_of_not_mdifferentiable_at
357    (h : ¬ mdifferentiable_at I I' f x) : mfderiv I I' f x = 0 :=
id           └────────────────┘  └┘      └─────┘  └┘   
src          └────────────────┘             └─────┘          
typ          └────────────────┘  └┘      └─────┘  └┘   
doc           └────────────────┘             └─────┘
358  by { simp [mfderiv, h], refl }
id              └─────┘  
src       └────┘└─────┘└┘   └───┘
typ       └────┘└─────┘└┘  └───┘
doc       └────┘└─────┘└┘   └───┘
txt       └────┘       └┘   └───┘
par       └────┘       └┘   └───┘
pid                  └┘       
st     └──────────────────┘└─────┘└┘
359  
360  theorem has_mfderiv_within_at.mono (h : has_mfderiv_within_at I I' f t x f') (hst : s ⊆ t) :
id                                           └───────────────────┘  └┘    └┘           
src                                          └───────────────────┘                         
typ                                          └───────────────────┘  └┘    └┘           
doc                                          └───────────────────┘
361    has_mfderiv_within_at I I' f s x f' :=
id     └───────────────────┘  └┘    └┘
src    └───────────────────┘
typ    └───────────────────┘  └┘    └┘
doc    └───────────────────┘
362  ⟨ continuous_within_at.mono h.1 hst,
id     └───────────────────────┘   └─┘
src    └───────────────────────┘  
typ    └───────────────────────┘   └─┘
363    has_fderiv_within_at.mono h.2 (inter_subset_inter (preimage_mono hst) (subset.refl _)) ⟩
id     └───────────────────────┘    └────────────────┘  └───────────┘ └─┘   └─────────┘
src    └───────────────────────┘     └────────────────┘  └───────────┘       └─────────┘
typ    └───────────────────────┘    └────────────────┘  └───────────┘ └─┘   └─────────┘
364  
365  theorem has_mfderiv_at.has_mfderiv_within_at
366    (h : has_mfderiv_at I I' f x f') : has_mfderiv_within_at I I' f s x f' :=
id          └────────────┘  └┘   └┘    └───────────────────┘  └┘    └┘
src         └────────────┘                └───────────────────┘
typ         └────────────┘  └┘   └┘    └───────────────────┘  └┘    └┘
doc         └────────────┘                └───────────────────┘
367  ⟨ continuous_at.continuous_within_at h.1, has_fderiv_within_at.mono h.2 (inter_subset_right _ _) ⟩
id     └────────────────────────────────┘    └───────────────────────┘    └────────────────┘
src    └────────────────────────────────┘     └───────────────────────┘     └────────────────┘
typ    └────────────────────────────────┘    └───────────────────────┘    └────────────────┘
368  
369  lemma has_mfderiv_within_at.mdifferentiable_within_at (h : has_mfderiv_within_at I I' f s x f') :
id                                                              └───────────────────┘  └┘    └┘
src                                                             └───────────────────┘
typ                                                             └───────────────────┘  └┘    └┘
doc                                                             └───────────────────┘
370    mdifferentiable_within_at I I' f s x :=
id     └───────────────────────┘  └┘   
src    └───────────────────────┘
typ    └───────────────────────┘  └┘   
doc    └───────────────────────┘
371  ⟨h.1, ⟨f', h.2⟩⟩
id        └┘  
src             
typ       └┘  
372  
373  lemma has_mfderiv_at.mdifferentiable_at (h : has_mfderiv_at I I' f x f') :
id                                                └────────────┘  └┘   └┘
src                                               └────────────┘
typ                                               └────────────┘  └┘   └┘
doc                                               └────────────┘
374    mdifferentiable_at I I' f x :=
id     └────────────────┘  └┘  
src    └────────────────┘
typ    └────────────────┘  └┘  
doc    └────────────────┘
375  ⟨h.1, ⟨f', h.2⟩⟩
id        └┘  
src             
typ       └┘  
376  
377  @[simp] lemma has_mfderiv_within_at_univ :
doc    └──┘
378    has_mfderiv_within_at I I' f univ x f' ↔ has_mfderiv_at I I' f x f' :=
id     └───────────────────┘  └┘  └──┘  └┘  └────────────┘  └┘   └┘
src    └───────────────────┘        └──┘       └────────────┘
typ    └───────────────────┘  └┘  └──┘  └┘  └────────────┘  └┘   └┘
doc    └───────────────────┘                    └────────────┘
379  by simp [has_mfderiv_within_at, has_mfderiv_at, continuous_within_at_univ]
id            └───────────────────┘  └────────────┘  └───────────────────────┘
src     └────┘└───────────────────┘└┘└────────────┘└┘└───────────────────────┘└─
typ     └────┘└───────────────────┘└┘└────────────┘└┘└───────────────────────┘└─
doc     └────┘└───────────────────┘└┘└────────────┘└┘                         └─
txt     └────┘                     └┘              └┘                         └─
par     └────┘                     └┘              └┘                         └─
pid                              └┘              └┘                         
st     └────────────────────────────────────────────────────────────────────────
380  
src  
typ  
doc  
txt  
par  
pid  
st   
381  theorem has_mfderiv_at_unique
382    (h₀ : has_mfderiv_at I I' f x f₀') (h₁ : has_mfderiv_at I I' f x f₁') : f₀' = f₁' :=
id           └────────────┘  └┘   └─┘        └────────────┘  └┘   └─┘    └─┘  └─┘
src          └────────────┘                     └────────────┘                     
typ          └────────────┘  └┘   └─┘        └────────────┘  └┘   └─┘    └─┘  └─┘
doc          └────────────┘                     └────────────┘
383  begin
st   └─────
384    rw ← has_mfderiv_within_at_univ at h₀ h₁,
id          └────────────────────────┘
src    └───┘└────────────────────────┘└───────┘
typ    └───┘└────────────────────────┘└───────┘
doc    └───┘                          └───────┘
txt    └───┘                          └───────┘
par    └───┘                          └───────┘
pid      └─┘                          └───────┘
st   ─────────────────────────────────────────┘└─
385    exact (unique_mdiff_within_at_univ I).eq h₀ h₁
id            └─────────────────────────┘      └┘ └┘
src    └────┘ └─────────────────────────┘ └───┘    
typ    └────┘ └─────────────────────────┘└───┘└┘└┘
doc    └────┘                             └───┘    
txt    └────┘                             └───┘    
par    └────┘                             └───┘    
pid                                      └───┘    
st   ────────────────────────────────────────────────┘
386  end
st   └─┘
387  
388  lemma has_mfderiv_within_at_inter' (h : t ∈ nhds_within x s) :
id                                             └─────────┘  
src                                             └─────────┘
typ                                            └─────────┘  
doc                                              └─────────┘
389    has_mfderiv_within_at I I' f (s ∩ t) x f' ↔ has_mfderiv_within_at I I' f s x f' :=
id     └───────────────────┘  └┘        └┘  └───────────────────┘  └┘    └┘
src    └───────────────────┘                     └───────────────────┘
typ    └───────────────────┘  └┘        └┘  └───────────────────┘  └┘    └┘
doc    └───────────────────┘                       └───────────────────┘
390  begin
st   └─────
391    rw [has_mfderiv_within_at, has_mfderiv_within_at, ext_chart_preimage_inter_eq,
id         └───────────────────┘  └───────────────────┘  └─────────────────────────┘
src    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
typ    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
doc    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
txt    └──┘                     └┘                     └┘                           └─
par    └──┘                     └┘                     └┘                           └─
pid      └┘                     └┘                     └┘                           └─
st   ──────────────────────────┘└─────────────────────┘└───────────────────────────┘└─
392        has_fderiv_within_at_inter', continuous_within_at_inter' h],
id         └─────────────────────────┘  └─────────────────────────┘ 
src  ─────┘└─────────────────────────┘└┘└─────────────────────────┘ 
typ  ─────┘└─────────────────────────┘└┘└─────────────────────────┘
doc  ─────┘                           └┘                            
txt  ─────┘                           └┘                            
par  ─────┘                           └┘                            
pid  ─────┘                           └┘                            
st   ────────────────────────────────┘└─────────────────────────────┘└──
393    exact ext_chart_preimage_mem_nhds_within I x h,
id           └────────────────────────────────┘   
src    └────┘└────────────────────────────────┘  
typ    └────┘└────────────────────────────────┘
doc    └────┘└────────────────────────────────┘  
txt    └────┘                                    
par    └────┘                                    
pid                                             
st   ───────────────────────────────────────────────┘└─
394  end
st   ──┘
395  
396  lemma has_mfderiv_within_at_inter (h : t ∈ 𝓝 x) :
id                                             
src                                            
typ                                            
doc                                             
397    has_mfderiv_within_at I I' f (s ∩ t) x f' ↔ has_mfderiv_within_at I I' f s x f' :=
id     └───────────────────┘  └┘        └┘  └───────────────────┘  └┘    └┘
src    └───────────────────┘                     └───────────────────┘
typ    └───────────────────┘  └┘        └┘  └───────────────────┘  └┘    └┘
doc    └───────────────────┘                       └───────────────────┘
398  begin
st   └─────
399    rw [has_mfderiv_within_at, has_mfderiv_within_at, ext_chart_preimage_inter_eq,
id         └───────────────────┘  └───────────────────┘  └─────────────────────────┘
src    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
typ    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
doc    └──┘└───────────────────┘└┘└───────────────────┘└┘└─────────────────────────┘└─
txt    └──┘                     └┘                     └┘                           └─
par    └──┘                     └┘                     └┘                           └─
pid      └┘                     └┘                     └┘                           └─
st   ──────────────────────────┘└─────────────────────┘└───────────────────────────┘└─
400        has_fderiv_within_at_inter, continuous_within_at_inter h],
id         └────────────────────────┘  └────────────────────────┘ 
src  ─────┘└────────────────────────┘└┘└────────────────────────┘ 
typ  ─────┘└────────────────────────┘└┘└────────────────────────┘
doc  ─────┘                          └┘                           
txt  ─────┘                          └┘                           
par  ─────┘                          └┘                           
pid  ─────┘                          └┘                           
st   ───────────────────────────────┘└────────────────────────────┘└──
401    exact ext_chart_preimage_mem_nhds I x h,
id           └─────────────────────────┘   
src    └────┘└─────────────────────────┘  
typ    └────┘└─────────────────────────┘
doc    └────┘└─────────────────────────┘  
txt    └────┘                             
par    └────┘                             
pid                                      
st   ────────────────────────────────────────┘└─
402  end
st   ──┘
403  
404  lemma has_mfderiv_within_at.union
405    (hs : has_mfderiv_within_at I I' f s x f') (ht : has_mfderiv_within_at I I' f t x f') :
id           └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └┘
src          └───────────────────┘                      └───────────────────┘
typ          └───────────────────┘  └┘    └┘        └───────────────────┘  └┘    └┘
doc          └───────────────────┘                      └───────────────────┘
406    has_mfderiv_within_at I I' f (s ∪ t) x f' :=
id     └───────────────────┘  └┘        └┘
src    └───────────────────┘           
typ    └───────────────────┘  └┘        └┘
doc    └───────────────────┘
407  begin
st   └─────
408    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
409    { exact continuous_within_at.union hs.1 ht.1 },
id             └────────────────────────┘ └┘   └┘
src      └────┘└────────────────────────┘  └─┘  └─┘
typ      └────┘└────────────────────────┘└┘└─┘└┘└─┘
doc      └────┘                            └─┘  └─┘
txt      └────┘                            └─┘  └─┘
par      └────┘                            └─┘  └─┘
pid                                       └─┘  └─┘
st   ───┘└─────────────────────────────────────────┘└┘
410    { convert has_fderiv_within_at.union hs.2 ht.2,
id               └────────────────────────┘ └┘   └┘
src      └──────┘└────────────────────────┘  └─┘  └┘
typ      └──────┘└────────────────────────┘└┘└─┘└┘└┘
doc      └──────┘                            └─┘  └┘
txt      └──────┘                            └─┘  └┘
par      └──────┘                            └─┘  └┘
pid                                         └─┘  └┘
st   ───────────────────────────────────────────────┘└─
411      simp [union_inter_distrib_right] }
id             └───────────────────────┘
src      └────┘└───────────────────────┘└┘
typ      └────┘└───────────────────────┘└┘
doc      └────┘                         └┘
txt      └────┘                         └┘
par      └────┘                         └┘
pid                                   
st   ────────────────────────────────────┘└─
412  end
st   ──┘
413  
414  lemma has_mfderiv_within_at.nhds_within (h : has_mfderiv_within_at I I' f s x f')
id                                                └───────────────────┘  └┘    └┘
src                                               └───────────────────┘
typ                                               └───────────────────┘  └┘    └┘
doc                                               └───────────────────┘
415    (ht : s ∈ nhds_within x t) : has_mfderiv_within_at I I' f t x f' :=
id             └─────────┘      └───────────────────┘  └┘    └┘
src             └─────────┘        └───────────────────┘
typ            └─────────┘      └───────────────────┘  └┘    └┘
doc              └─────────┘        └───────────────────┘
416  (has_mfderiv_within_at_inter' ht).1 (h.mono (inter_subset_right _ _))
id    └──────────────────────────┘ └┘    └───┘  └────────────────┘
src   └──────────────────────────┘        └───┘  └────────────────┘
typ   └──────────────────────────┘ └┘    └───┘  └────────────────┘
417  
418  lemma has_mfderiv_within_at.has_mfderiv_at (h : has_mfderiv_within_at I I' f s x f') (hs : s ∈ 𝓝 x) :
id                                                   └───────────────────┘  └┘    └┘           
src                                                  └───────────────────┘                         
typ                                                  └───────────────────┘  └┘    └┘           
doc                                                  └───────────────────┘                          
419    has_mfderiv_at I I' f x f' :=
id     └────────────┘  └┘   └┘
src    └────────────┘
typ    └────────────┘  └┘   └┘
doc    └────────────┘
420  by rwa [← univ_inter s, has_mfderiv_within_at_inter hs, has_mfderiv_within_at_univ] at h
id             └────────┘   └─────────────────────────┘ └┘  └────────────────────────┘
src     └─────┘└────────┘ └┘└─────────────────────────┘  └┘└────────────────────────┘└──────
typ     └─────┘└────────┘└┘└─────────────────────────┘└┘└┘└────────────────────────┘└──────
doc     └─────┘           └┘                             └┘                          └──────
txt     └─────┘           └┘                             └┘                          └──────
par     └─────┘           └┘                             └┘                          └──────
pid        └──┘           └┘                             └┘                          └───┘
st     └──────────────────┘└──────────────────────────────┘└──────────────────────────┘└─────
421  
src  
typ  
doc  
txt  
par  
pid  
st   
422  lemma mdifferentiable_within_at.has_mfderiv_within_at (h : mdifferentiable_within_at I I' f s x) :
id                                                              └───────────────────────┘  └┘   
src                                                             └───────────────────────┘
typ                                                             └───────────────────────┘  └┘   
doc                                                             └───────────────────────┘
423    has_mfderiv_within_at I I' f s x (mfderiv_within I I' f s x) :=
id     └───────────────────┘  └┘     └────────────┘  └┘   
src    └───────────────────┘             └────────────┘
typ    └───────────────────┘  └┘     └────────────┘  └┘   
doc    └───────────────────┘             └────────────┘
424  begin
st   └─────
425    refine ⟨h.1, _⟩,
id             
src    └─────┘  └────┘
typ    └─────┘ └────┘
doc    └─────┘  └────┘
txt    └─────┘  └────┘
par    └─────┘  └────┘
pid            └────┘
st   ────────────────┘└─
426    simp [mfderiv_within, h],
id           └────────────┘  
src    └────┘└────────────┘└┘ 
typ    └────┘└────────────┘└┘
doc    └────┘└────────────┘└┘ 
txt    └────┘              └┘ 
par    └────┘              └┘ 
pid                      └┘ 
st   ─────────────────────────┘└─
427    exact differentiable_within_at.has_fderiv_within_at h.2
id           └───────────────────────────────────────────┘ 
src    └────┘└───────────────────────────────────────────┘ └─┘
typ    └────┘└───────────────────────────────────────────┘└─┘
doc    └────┘                                              └─┘
txt    └────┘                                              └─┘
par    └────┘                                              └─┘
pid                                                       └─┘
st   ─────────────────────────────────────────────────────────┘
428  end
st   └─┘
429  
430  lemma mdifferentiable_within_at.mfderiv_within (h : mdifferentiable_within_at I I' f s x) :
id                                                       └───────────────────────┘  └┘   
src                                                      └───────────────────────┘
typ                                                      └───────────────────────┘  └┘   
doc                                                      └───────────────────────┘
431    (mfderiv_within I I' f s x) =
id      └────────────┘  └┘     
src     └────────────┘             
typ     └────────────┘  └┘     
doc     └────────────┘
432    fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : _) ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun)
id     └───────────┘   └─────────────────────┘  └┘          └──────────┘   └─────┘  └─┘   └───┘ └─────┘
src    └───────────┘    └─────────────────────┘                 └──────────┘     └─────┘  └─┘    └───┘  └─────┘
typ    └───────────┘   └─────────────────────┘  └┘          └──────────┘   └─────┘  └─┘   └───┘ └─────┘
doc    └───────────┘    └─────────────────────┘                 └──────────┘              └─┘     └───┘
433    ((ext_chart_at I x).to_fun x) :=
id       └──────────┘   └────┘  
src      └──────────┘     └────┘
typ      └──────────┘   └────┘  
doc      └──────────┘
434  by simp [mfderiv_within, h]
id            └────────────┘  
src     └────┘└────────────┘└┘ └─
typ     └────┘└────────────┘└┘└─
doc     └────┘└────────────┘└┘ └─
txt     └────┘              └┘ └─
par     └────┘              └┘ └─
pid                       └┘ 
st     └─────────────────────────
435  
src  
typ  
doc  
txt  
par  
pid  
st   
436  lemma mdifferentiable_at.has_mfderiv_at (h : mdifferentiable_at I I' f x) :
id                                                └────────────────┘  └┘  
src                                               └────────────────┘
typ                                               └────────────────┘  └┘  
doc                                               └────────────────┘
437    has_mfderiv_at I I' f x (mfderiv I I' f x) :=
id     └────────────┘  └┘    └─────┘  └┘  
src    └────────────┘           └─────┘
typ    └────────────┘  └┘    └─────┘  └┘  
doc    └────────────┘           └─────┘
438  begin
st   └─────
439    refine ⟨h.1, _⟩,
id             
src    └─────┘  └────┘
typ    └─────┘ └────┘
doc    └─────┘  └────┘
txt    └─────┘  └────┘
par    └─────┘  └────┘
pid            └────┘
st   ────────────────┘└─
440    simp [mfderiv, h],
id           └─────┘  
src    └────┘└─────┘└┘ 
typ    └────┘└─────┘└┘
doc    └────┘└─────┘└┘ 
txt    └────┘       └┘ 
par    └────┘       └┘ 
pid               └┘ 
st   ──────────────────┘└─
441    exact differentiable_within_at.has_fderiv_within_at h.2
id           └───────────────────────────────────────────┘ 
src    └────┘└───────────────────────────────────────────┘ └─┘
typ    └────┘└───────────────────────────────────────────┘└─┘
doc    └────┘                                              └─┘
txt    └────┘                                              └─┘
par    └────┘                                              └─┘
pid                                                       └─┘
st   ─────────────────────────────────────────────────────────┘
442  end
st   └─┘
443  
444  lemma mdifferentiable_at.mfderiv (h : mdifferentiable_at I I' f x) :
id                                         └────────────────┘  └┘  
src                                        └────────────────┘
typ                                        └────────────────┘  └┘  
doc                                        └────────────────┘
445    (mfderiv I I' f x) =
id      └─────┘  └┘    
src     └─────┘           
typ     └─────┘  └┘    
doc     └─────┘
446    fderiv_within 𝕜 (written_in_ext_chart_at I I' x f : _) (range I.to_fun) ((ext_chart_at I x).to_fun x) :=
id     └───────────┘   └─────────────────────┘  └┘         └───┘ └─────┘    └──────────┘   └────┘  
src    └───────────┘    └─────────────────────┘                └───┘  └─────┘    └──────────┘     └────┘
typ    └───────────┘   └─────────────────────┘  └┘         └───┘ └─────┘    └──────────┘   └────┘  
doc    └───────────┘    └─────────────────────┘                └───┘             └──────────┘
447  by simp [mfderiv, h]
id            └─────┘  
src     └────┘└─────┘└┘ └─
typ     └────┘└─────┘└┘└─
doc     └────┘└─────┘└┘ └─
txt     └────┘       └┘ └─
par     └────┘       └┘ └─
pid                └┘ 
st     └──────────────────
448  
src  
typ  
doc  
txt  
par  
pid  
st   
449  lemma has_mfderiv_at.mfderiv (h : has_mfderiv_at I I' f x f') :
id                                     └────────────┘  └┘   └┘
src                                    └────────────┘
typ                                    └────────────┘  └┘   └┘
doc                                    └────────────┘
450    mfderiv I I' f x = f' :=
id     └─────┘  └┘    └┘
src    └─────┘          
typ    └─────┘  └┘    └┘
doc    └─────┘
451  by { ext, rw has_mfderiv_at_unique h h.mdifferentiable_at.has_mfderiv_at }
id                └───────────────────┘   └─────────────────────────────────┘
src       └─┘  └─┘└───────────────────┘ └─────────────────────────────────┘
typ       └─┘  └─┘└───────────────────┘ └─────────────────────────────────┘
doc       └─┘  └─┘                                                         
txt       └─┘  └─┘                                                         
par       └─┘  └─┘                                                         
pid                                                                       
st     └────┘└───────────────────────────────────────────────────────────────┘└┘
452  
453  lemma has_mfderiv_within_at.mfderiv_within
454    (h : has_mfderiv_within_at I I' f s x f') (hxs : unique_mdiff_within_at I s x) :
id          └───────────────────┘  └┘    └┘         └────────────────────┘   
src         └───────────────────┘                       └────────────────────┘
typ         └───────────────────┘  └┘    └┘         └────────────────────┘   
doc         └───────────────────┘                       └────────────────────┘
455    mfderiv_within I I' f s x = f' :=
id     └────────────┘  └┘     └┘
src    └────────────┘            
typ    └────────────┘  └┘     └┘
doc    └────────────┘
456  by { ext, rw hxs.eq h h.mdifferentiable_within_at.has_mfderiv_within_at }
id                └────┘   └───────────────────────────────────────────────┘
src       └─┘  └─┘└────┘ └───────────────────────────────────────────────┘
typ       └─┘  └─┘└────┘ └───────────────────────────────────────────────┘
doc       └─┘  └─┘└────┘                                                  
txt       └─┘  └─┘                                                        
par       └─┘  └─┘                                                        
pid                                                                      
st     └────┘└──────────────────────────────────────────────────────────────┘└┘
457  
458  lemma mdifferentiable.mfderiv_within
459    (h : mdifferentiable_at I I' f x) (hxs : unique_mdiff_within_at I s x) :
id          └────────────────┘  └┘           └────────────────────┘   
src         └────────────────┘                  └────────────────────┘
typ         └────────────────┘  └┘           └────────────────────┘   
doc         └────────────────┘                  └────────────────────┘
460    mfderiv_within I I' f s x = mfderiv I I' f x :=
id     └────────────┘  └┘     └─────┘  └┘  
src    └────────────┘             └─────┘
typ    └────────────┘  └┘     └─────┘  └┘  
doc    └────────────┘              └─────┘
461  begin
st   └─────
462    apply has_mfderiv_within_at.mfderiv_within _ hxs,
id           └──────────────────────────────────┘   └─┘
src    └────┘└──────────────────────────────────┘└─┘
typ    └────┘└──────────────────────────────────┘└─┘└─┘
doc    └────┘                                    └─┘
txt    └────┘                                    └─┘
par    └────┘                                    └─┘
pid                                             └─┘
st   ─────────────────────────────────────────────────┘└─
463    exact h.has_mfderiv_at.has_mfderiv_within_at
id           └────────────────────────────────────┘
src    └────┘└────────────────────────────────────┘
typ    └────┘└────────────────────────────────────┘
doc    └────┘                                      
txt    └────┘                                      
par    └────┘                                      
pid                                               
st   ──────────────────────────────────────────────┘
464  end
st   └─┘
465  
466  lemma mfderiv_within_subset (st : s ⊆ t) (hs : unique_mdiff_within_at I s x)
id                                               └────────────────────┘   
src                                                └────────────────────┘
typ                                              └────────────────────┘   
doc                                                 └────────────────────┘
467    (h : mdifferentiable_within_at I I' f t x) :
id          └───────────────────────┘  └┘   
src         └───────────────────────┘
typ         └───────────────────────┘  └┘   
doc         └───────────────────────┘
468    mfderiv_within I I' f s x = mfderiv_within I I' f t x :=
id     └────────────┘  └┘     └────────────┘  └┘   
src    └────────────┘             └────────────┘
typ    └────────────┘  └┘     └────────────┘  └┘   
doc    └────────────┘              └────────────┘
469  ((mdifferentiable_within_at.has_mfderiv_within_at h).mono st).mfderiv_within hs
id     └─────────────────────────────────────────────┘  └──┘  └┘ └────────────┘  └┘
src    └─────────────────────────────────────────────┘   └──┘     └────────────┘
typ    └─────────────────────────────────────────────┘  └──┘  └┘ └────────────┘  └┘
470  
471  omit Is I's
472  
473  lemma mdifferentiable_within_at.mono (hst : s ⊆ t)
id                                                 
src                                                
typ                                                
474    (h : mdifferentiable_within_at I I' f t x) : mdifferentiable_within_at I I' f s x :=
id          └───────────────────────┘  └┘       └───────────────────────┘  └┘   
src         └───────────────────────┘               └───────────────────────┘
typ         └───────────────────────┘  └┘       └───────────────────────┘  └┘   
doc         └───────────────────────┘               └───────────────────────┘
475  ⟨ continuous_within_at.mono h.1 hst,
id     └───────────────────────┘   └─┘
src    └───────────────────────┘  
typ    └───────────────────────┘   └─┘
476    differentiable_within_at.mono h.2 (inter_subset_inter (preimage_mono hst) (subset.refl _)) ⟩
id     └───────────────────────────┘    └────────────────┘  └───────────┘ └─┘   └─────────┘
src    └───────────────────────────┘     └────────────────┘  └───────────┘       └─────────┘
typ    └───────────────────────────┘    └────────────────┘  └───────────┘ └─┘   └─────────┘
477  
478  lemma mdifferentiable_within_at_univ :
479    mdifferentiable_within_at I I' f univ x ↔ mdifferentiable_at I I' f x :=
id     └───────────────────────┘  └┘  └──┘   └────────────────┘  └┘  
src    └───────────────────────┘        └──┘    └────────────────┘
typ    └───────────────────────┘  └┘  └──┘   └────────────────┘  └┘  
doc    └───────────────────────┘                 └────────────────┘
480  by simp [mdifferentiable_within_at, mdifferentiable_at, continuous_within_at_univ]
id            └───────────────────────┘  └────────────────┘  └───────────────────────┘
src     └────┘└───────────────────────┘└┘└────────────────┘└┘└───────────────────────┘└─
typ     └────┘└───────────────────────┘└┘└────────────────┘└┘└───────────────────────┘└─
doc     └────┘└───────────────────────┘└┘└────────────────┘└┘                         └─
txt     └────┘                         └┘                  └┘                         └─
par     └────┘                         └┘                  └┘                         └─
pid                                  └┘                  └┘                         
st     └────────────────────────────────────────────────────────────────────────────────
481  
src  
typ  
doc  
txt  
par  
pid  
st   
482  lemma mdifferentiable_within_at_inter (ht : t ∈ 𝓝 x) :
id                                                  
src                                                 
typ                                                 
doc                                                  
483    mdifferentiable_within_at I I' f (s ∩ t) x ↔ mdifferentiable_within_at I I' f s x :=
id     └───────────────────────┘  └┘         └───────────────────────┘  └┘   
src    └───────────────────────┘                  └───────────────────────┘
typ    └───────────────────────┘  └┘         └───────────────────────┘  └┘   
doc    └───────────────────────┘                    └───────────────────────┘
484  begin
st   └─────
485    rw [mdifferentiable_within_at, mdifferentiable_within_at, ext_chart_preimage_inter_eq,
id         └───────────────────────┘  └───────────────────────┘  └─────────────────────────┘
src    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
typ    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
doc    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
txt    └──┘                         └┘                         └┘                           └─
par    └──┘                         └┘                         └┘                           └─
pid      └┘                         └┘                         └┘                           └─
st   ──────────────────────────────┘└─────────────────────────┘└───────────────────────────┘└─
486        differentiable_within_at_inter, continuous_within_at_inter ht],
id         └────────────────────────────┘  └────────────────────────┘ └┘
src  ─────┘└────────────────────────────┘└┘└────────────────────────┘  
typ  ─────┘└────────────────────────────┘└┘└────────────────────────┘└┘
doc  ─────┘                              └┘                            
txt  ─────┘                              └┘                            
par  ─────┘                              └┘                            
pid  ─────┘                              └┘                            
st   ───────────────────────────────────┘└─────────────────────────────┘└──
487    exact ext_chart_preimage_mem_nhds I x ht
id           └─────────────────────────┘   └┘
src    └────┘└─────────────────────────┘    
typ    └────┘└─────────────────────────┘└┘
doc    └────┘└─────────────────────────┘    
txt    └────┘                               
par    └────┘                               
pid                                        
st   ──────────────────────────────────────────┘
488  end
st   └─┘
489  
490  lemma mdifferentiable_within_at_inter' (ht : t ∈ nhds_within x s) :
id                                                  └─────────┘  
src                                                  └─────────┘
typ                                                 └─────────┘  
doc                                                   └─────────┘
491    mdifferentiable_within_at I I' f (s ∩ t) x ↔ mdifferentiable_within_at I I' f s x :=
id     └───────────────────────┘  └┘         └───────────────────────┘  └┘   
src    └───────────────────────┘                  └───────────────────────┘
typ    └───────────────────────┘  └┘         └───────────────────────┘  └┘   
doc    └───────────────────────┘                    └───────────────────────┘
492  begin
st   └─────
493    rw [mdifferentiable_within_at, mdifferentiable_within_at, ext_chart_preimage_inter_eq,
id         └───────────────────────┘  └───────────────────────┘  └─────────────────────────┘
src    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
typ    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
doc    └──┘└───────────────────────┘└┘└───────────────────────┘└┘└─────────────────────────┘└─
txt    └──┘                         └┘                         └┘                           └─
par    └──┘                         └┘                         └┘                           └─
pid      └┘                         └┘                         └┘                           └─
st   ──────────────────────────────┘└─────────────────────────┘└───────────────────────────┘└─
494        differentiable_within_at_inter', continuous_within_at_inter' ht],
id         └─────────────────────────────┘  └─────────────────────────┘ └┘
src  ─────┘└─────────────────────────────┘└┘└─────────────────────────┘  
typ  ─────┘└─────────────────────────────┘└┘└─────────────────────────┘└┘
doc  ─────┘                               └┘                             
txt  ─────┘                               └┘                             
par  ─────┘                               └┘                             
pid  ─────┘                               └┘                             
st   ────────────────────────────────────┘└──────────────────────────────┘└──
495    exact ext_chart_preimage_mem_nhds_within I x ht
id           └────────────────────────────────┘   └┘
src    └────┘└────────────────────────────────┘    
typ    └────┘└────────────────────────────────┘└┘
doc    └────┘└────────────────────────────────┘    
txt    └────┘                                      
par    └────┘                                      
pid                                               
st   ─────────────────────────────────────────────────┘
496  end
st   └─┘
497  
498  lemma mdifferentiable_at.mdifferentiable_within_at
499    (h : mdifferentiable_at I I' f x) : mdifferentiable_within_at I I' f s x :=
id          └────────────────┘  └┘      └───────────────────────┘  └┘   
src         └────────────────┘             └───────────────────────┘
typ         └────────────────┘  └┘      └───────────────────────┘  └┘   
doc         └────────────────┘             └───────────────────────┘
500  mdifferentiable_within_at.mono (subset_univ _) (mdifferentiable_within_at_univ.2 h)
id   └────────────────────────────┘  └─────────┘     └────────────────────────────┘  
src  └────────────────────────────┘  └─────────┘     └────────────────────────────┘
typ  └────────────────────────────┘  └─────────┘     └────────────────────────────┘  
501  
502  lemma mdifferentiable_within_at.mdifferentiable_at
503    (h : mdifferentiable_within_at I I' f s x) (hs : s ∈ 𝓝 x) : mdifferentiable_at I I' f x :=
id          └───────────────────────┘  └┘                  └────────────────┘  └┘  
src         └───────────────────────┘                            └────────────────┘
typ         └───────────────────────┘  └┘                  └────────────────┘  └┘  
doc         └───────────────────────┘                             └────────────────┘
504  begin
st   └─────
505    have : s = univ ∩ s, by rw univ_inter,
id               └──┘          └────────┘
src    └─────┘ └──┘      └─┘└────────┘
typ    └─────┘ └──┘     └─┘└────────┘
doc    └─────┘             └─┘
txt    └─────┘             └─┘
par    └─────┘             └─┘
pid    └───┘└┘               
st   ────────────────────┘        └────────┘└─
506    rwa [this, mdifferentiable_within_at_inter hs, mdifferentiable_within_at_univ] at h,
id          └──┘  └─────────────────────────────┘ └┘  └────────────────────────────┘
src    └───┘    └┘└─────────────────────────────┘  └┘└────────────────────────────┘└────┘
typ    └───┘└──┘└┘└─────────────────────────────┘└┘└┘└────────────────────────────┘└────┘
doc    └───┘    └┘                                 └┘                              └────┘
txt    └───┘    └┘                                 └┘                              └────┘
par    └───┘    └┘                                 └┘                              └────┘
pid       └┘    └┘                                 └┘                              └───┘
st   ──────────┘└──────────────────────────────────┘└──────────────────────────────┘└───┘└─
507  end
st   ──┘
508  
509  lemma mdifferentiable_on.mono
510    (h : mdifferentiable_on I I' f t) (st : s ⊆ t) : mdifferentiable_on I I' f s :=
id          └────────────────┘  └┘                └────────────────┘  └┘  
src         └────────────────┘                         └────────────────┘
typ         └────────────────┘  └┘                └────────────────┘  └┘  
doc         └────────────────┘                          └────────────────┘
511  λx hx, (h x (st hx)).mono st
id     └┘      └┘ └┘  └──┘  └┘
src                      └──┘
typ    └┘      └┘ └┘  └──┘  └┘
512  
513  lemma mdifferentiable_on_univ :
514    mdifferentiable_on I I' f univ ↔ mdifferentiable I I' f :=
id     └────────────────┘  └┘  └──┘  └─────────────┘  └┘ 
src    └────────────────┘        └──┘  └─────────────┘
typ    └────────────────┘  └┘  └──┘  └─────────────┘  └┘ 
doc    └────────────────┘               └─────────────┘
515  by { simp [mdifferentiable_on, mdifferentiable_within_at_univ], refl }
id              └────────────────┘  └────────────────────────────┘
src       └────┘└────────────────┘└┘└────────────────────────────┘  └───┘
typ       └────┘└────────────────┘└┘└────────────────────────────┘  └───┘
doc       └────┘└────────────────┘└┘                                └───┘
txt       └────┘                  └┘                                └───┘
par       └────┘                  └┘                                └───┘
pid                             └┘                                    
st     └──────────────────────────────────────────────────────────┘└─────┘└┘
516  
517  lemma mdifferentiable.mdifferentiable_on
518    (h : mdifferentiable I I' f) : mdifferentiable_on I I' f s :=
id          └─────────────┘  └┘     └────────────────┘  └┘  
src         └─────────────┘           └────────────────┘
typ         └─────────────┘  └┘     └────────────────┘  └┘  
doc         └─────────────┘           └────────────────┘
519  (mdifferentiable_on_univ.2 h).mono (subset_univ _)
id    └─────────────────────┘   └──┘   └─────────┘
src   └─────────────────────┘    └──┘   └─────────┘
typ   └─────────────────────┘   └──┘   └─────────┘
520  
521  lemma mdifferentiable_on_of_locally_mdifferentiable_on
522    (h : ∀x∈s, ∃u, is_open u ∧ x ∈ u ∧ mdifferentiable_on I I' f (s ∩ u)) : mdifferentiable_on I I' f s :=
id               └─────┘       └────────────────┘  └┘          └────────────────┘  └┘  
src                 └─────┘          └────────────────┘                  └────────────────┘
typ              └─────┘       └────────────────┘  └┘          └────────────────┘  └┘  
doc                   └─────┘             └────────────────┘                   └────────────────┘
523  begin
st   └─────
524    assume x xs,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid    └─────────┘
st   ────────────┘└─
525    rcases h x xs with ⟨t, t_open, xt, ht⟩,
id              └┘
src    └─────┘    └───────────────────────┘
typ    └─────┘└┘└───────────────────────┘
doc    └─────┘    └───────────────────────┘
txt    └─────┘    └───────────────────────┘
par    └─────┘    └───────────────────────┘
pid              └───────────────────────┘
st   ───────────────────────────────────────┘└─
526    exact (mdifferentiable_within_at_inter (mem_nhds_sets t_open xt)).1 (ht x ⟨xs, xt⟩)
id            └─────────────────────────────┘  └───────────┘ └────┘         └┘   └┘  └┘
src    └────┘ └─────────────────────────────┘ └───────────┘        └───┘       └┘  └─┘
typ    └────┘ └─────────────────────────────┘ └───────────┘└────┘  └───┘ └┘ └┘└┘└┘└─┘
doc    └────┘                                                      └───┘       └┘  └─┘
txt    └────┘                                                      └───┘       └┘  └─┘
par    └────┘                                                      └───┘       └┘  └─┘
pid                                                               └───┘       └┘  └┘
st   ─────────────────────────────────────────────────────────────────────────────────────┘
527  end
st   └─┘
528  
529  include Is I's
530  @[simp] lemma mfderiv_within_univ : mfderiv_within I I' f univ = mfderiv I I' f :=
id                                       └────────────┘  └┘  └──┘  └─────┘  └┘ 
src                                      └────────────┘        └──┘  └─────┘
typ                                      └────────────┘  └┘  └──┘  └─────┘  └┘ 
doc    └──┘                              └────────────┘               └─────┘
531  begin
st   └─────
532    ext x : 1,
src    └───────┘
typ    └───────┘
doc    └───────┘
txt    └───────┘
par    └───────┘
pid       └┘└─┘
st   ──────────┘└─
533    simp [mfderiv_within, mfderiv],
id           └────────────┘  └─────┘
src    └────┘└────────────┘└┘└─────┘
typ    └────┘└────────────┘└┘└─────┘
doc    └────┘└────────────┘└┘└─────┘
txt    └────┘              └┘       
par    └────┘              └┘       
pid                      └┘       
st   ───────────────────────────────┘└─
534    erw mdifferentiable_within_at_univ
id         └────────────────────────────┘
src    └──┘└────────────────────────────┘
typ    └──┘└────────────────────────────┘
doc    └──┘                              
txt    └──┘                              
par    └──┘                              
pid                                     
st   ────────────────────────────────────┘
535  end
st   └─┘
536  
537  lemma mfderiv_within_inter (ht : t ∈ 𝓝 x) (hs : unique_mdiff_within_at I s x) :
id                                               └────────────────────┘   
src                                                └────────────────────┘
typ                                              └────────────────────┘   
doc                                                 └────────────────────┘
538    mfderiv_within I I' f (s ∩ t) x = mfderiv_within I I' f s x :=
id     └────────────┘  └┘         └────────────┘  └┘   
src    └────────────┘                  └────────────┘
typ    └────────────┘  └┘         └────────────┘  └┘   
doc    └────────────┘                    └────────────┘
539  by erw [mfderiv_within, mfderiv_within, ext_chart_preimage_inter_eq,
id           └────────────┘  └────────────┘  └─────────────────────────┘
src     └───┘└────────────┘└┘└────────────┘└┘└─────────────────────────┘└─
typ     └───┘└────────────┘└┘└────────────┘└┘└─────────────────────────┘└─
doc     └───┘└────────────┘└┘└────────────┘└┘└─────────────────────────┘└─
txt     └───┘              └┘              └┘                           └─
par     └───┘              └┘              └┘                           └─
pid        └┘              └┘              └┘                           └─
st     └──────────────────┘└──────────────┘└───────────────────────────┘└─
540    mdifferentiable_within_at_inter ht, fderiv_within_inter (ext_chart_preimage_mem_nhds I x ht) hs]
id     └─────────────────────────────┘ └┘  └─────────────────┘  └─────────────────────────┘   └┘  └┘
src  ─┘└─────────────────────────────┘  └┘└─────────────────┘ └─────────────────────────┘    └┘  └─
typ  ─┘└─────────────────────────────┘└┘└┘└─────────────────┘ └─────────────────────────┘└┘└┘└┘└─
doc  ─┘                                 └┘                    └─────────────────────────┘    └┘  └─
txt  ─┘                                 └┘                                                   └┘  └─
par  ─┘                                 └┘                                                   └┘  └─
pid  ─┘                                 └┘                                                   └┘  
st   ───────────────────────────────────┘└───────────────────────────────────────────────────────────┘
541  
src  
typ  
doc  
txt  
par  
pid  
st   
542  omit Is I's
543  
544  /-! ### Deriving continuity from differentiability on manifolds -/
545  
546  theorem has_mfderiv_within_at.continuous_within_at
547    (h : mdifferentiable_within_at I I' f s x) : continuous_within_at f s x :=
id          └───────────────────────┘  └┘       └──────────────────┘   
src         └───────────────────────┘               └──────────────────┘
typ         └───────────────────────┘  └┘       └──────────────────┘   
doc         └───────────────────────┘               └──────────────────┘
548  h.1
id   
src   
typ  
549  
550  theorem has_mfderiv_at.continuous_at (h : has_mfderiv_at I I' f x f') :
id                                             └────────────┘  └┘   └┘
src                                            └────────────┘
typ                                            └────────────┘  └┘   └┘
doc                                            └────────────┘
551    continuous_at f x :=
id     └───────────┘  
src    └───────────┘
typ    └───────────┘  
doc    └───────────┘
552  h.1
id   
src   
typ  
553  
554  lemma mdifferentiable_within_at.continuous_within_at (h : mdifferentiable_within_at I I' f s x) :
id                                                             └───────────────────────┘  └┘   
src                                                            └───────────────────────┘
typ                                                            └───────────────────────┘  └┘   
doc                                                            └───────────────────────┘
555    continuous_within_at f s x :=
id     └──────────────────┘   
src    └──────────────────┘
typ    └──────────────────┘   
doc    └──────────────────┘
556  h.1
id   
src   
typ  
557  
558  lemma mdifferentiable_at.continuous_at (h : mdifferentiable_at I I' f x) : continuous_at f x :=
id                                               └────────────────┘  └┘      └───────────┘  
src                                              └────────────────┘             └───────────┘
typ                                              └────────────────┘  └┘      └───────────┘  
doc                                              └────────────────┘             └───────────┘
559  h.1
id   
src   
typ  
560  
561  lemma mdifferentiable_on.continuous_on (h : mdifferentiable_on I I' f s) : continuous_on f s :=
id                                               └────────────────┘  └┘      └───────────┘  
src                                              └────────────────┘             └───────────┘
typ                                              └────────────────┘  └┘      └───────────┘  
doc                                              └────────────────┘             └───────────┘
562  λx hx, (h x hx).continuous_within_at
id     └┘     └┘ └──────────────────┘
src                 └──────────────────┘
typ    └┘     └┘ └──────────────────┘
563  
564  lemma mdifferentiable.continuous (h : mdifferentiable I I' f) : continuous f :=
id                                         └─────────────┘  └┘     └────────┘ 
src                                        └─────────────┘           └────────┘
typ                                        └─────────────┘  └┘     └────────┘ 
doc                                        └─────────────┘           └────────┘
565  continuous_iff_continuous_at.2 $ λx, (h x).continuous_at
id   └──────────────────────────┘          └───────────┘
src  └──────────────────────────┘             └───────────┘
typ  └──────────────────────────┘          └───────────┘
566  
567  include Is I's
568  lemma bundle_mfderiv_within_subset {p : tangent_bundle I M}
id                                           └────────────┘  
src                                          └────────────┘
typ                                          └────────────┘  
doc                                          └────────────┘
569    (st : s ⊆ t) (hs : unique_mdiff_within_at I s p.1) (h : mdifferentiable_within_at I I' f t p.1) :
id                     └────────────────────┘           └───────────────────────┘  └┘   
src                      └────────────────────┘              └───────────────────────┘           
typ                    └────────────────────┘           └───────────────────────┘  └┘   
doc                       └────────────────────┘               └───────────────────────┘
570    bundle_mfderiv_within I I' f s p = bundle_mfderiv_within I I' f t p :=
id     └───────────────────┘  └┘     └───────────────────┘  └┘   
src    └───────────────────┘             └───────────────────┘
typ    └───────────────────┘  └┘     └───────────────────┘  └┘   
doc    └───────────────────┘              └───────────────────┘
571  by { simp [bundle_mfderiv_within], rw mfderiv_within_subset st hs h }
id              └───────────────────┘      └───────────────────┘ └┘ └┘ 
src       └────┘└───────────────────┘  └─┘└───────────────────┘     
typ       └────┘└───────────────────┘  └─┘└───────────────────┘└┘└┘
doc       └────┘└───────────────────┘  └─┘                          
txt       └────┘                       └─┘                          
par       └────┘                       └─┘                          
pid                                                              
st     └─────────────────────────────┘└─────────────────────────────────┘└┘
572  
573  lemma bundle_mfderiv_within_univ :
574    bundle_mfderiv_within I I' f univ = bundle_mfderiv I I' f :=
id     └───────────────────┘  └┘  └──┘  └────────────┘  └┘ 
src    └───────────────────┘        └──┘  └────────────┘
typ    └───────────────────┘  └┘  └──┘  └────────────┘  └┘ 
doc    └───────────────────┘               └────────────┘
575  by { ext p : 1, simp [bundle_mfderiv_within, bundle_mfderiv], rw mfderiv_within_univ }
id                         └───────────────────┘  └────────────┘      └─────────────────┘
src       └───────┘  └────┘└───────────────────┘└┘└────────────┘  └─┘└─────────────────┘
typ       └───────┘  └────┘└───────────────────┘└┘└────────────┘  └─┘└─────────────────┘
doc       └───────┘  └────┘└───────────────────┘└┘└────────────┘  └─┘                   
txt       └───────┘  └────┘                     └┘                └─┘                   
par       └───────┘  └────┘                     └┘                └─┘                   
pid          └┘└─┘                           └┘                                     
st     └──────────┘└────────────────────────────────────────────┘└───────────────────────┘└┘
576  
577  lemma bundle_mfderiv_within_eq_bundle_mfderiv {p : tangent_bundle I M}
id                                                      └────────────┘  
src                                                     └────────────┘
typ                                                     └────────────┘  
doc                                                     └────────────┘
578    (hs : unique_mdiff_within_at I s p.1) (h : mdifferentiable_at I I' f p.1) :
id           └────────────────────┘           └────────────────┘  └┘  
src          └────────────────────┘              └────────────────┘         
typ          └────────────────────┘           └────────────────┘  └┘  
doc          └────────────────────┘               └────────────────┘
579    bundle_mfderiv_within I I' f s p = bundle_mfderiv I I' f p :=
id     └───────────────────┘  └┘     └────────────┘  └┘  
src    └───────────────────┘             └────────────┘
typ    └───────────────────┘  └┘     └────────────┘  └┘  
doc    └───────────────────┘              └────────────┘
580  begin
st   └─────
581    rw ← mdifferentiable_within_at_univ at h,
id          └────────────────────────────┘
src    └───┘└────────────────────────────┘└───┘
typ    └───┘└────────────────────────────┘└───┘
doc    └───┘                              └───┘
txt    └───┘                              └───┘
par    └───┘                              └───┘
pid      └─┘                              └───┘
st   ─────────────────────────────────────────┘└─
582    rw ← bundle_mfderiv_within_univ,
id          └────────────────────────┘
src    └───┘└────────────────────────┘
typ    └───┘└────────────────────────┘
doc    └───┘
txt    └───┘
par    └───┘
pid      └─┘
st   ────────────────────────────────┘└─
583    exact bundle_mfderiv_within_subset (subset_univ _) hs h,
id           └──────────────────────────┘  └─────────┘    └┘ 
src    └────┘└──────────────────────────┘ └─────────┘└──┘  
typ    └────┘└──────────────────────────┘ └─────────┘└──┘└┘
doc    └────┘                                        └──┘  
txt    └────┘                                        └──┘  
par    └────┘                                        └──┘  
pid                                                 └──┘  
st   ────────────────────────────────────────────────────────┘└─
584  end
st   ──┘
585  
586  @[simp] lemma bundle_mfderiv_within_tangent_bundle_proj {p : tangent_bundle I M} :
id                                                                └────────────┘  
src                                                               └────────────┘
typ                                                               └────────────┘  
doc    └──┘                                                       └────────────┘
587    tangent_bundle.proj I' M' (bundle_mfderiv_within I I' f s p) = f (tangent_bundle.proj I M p) := rfl
id     └─────────────────┘ └┘ └┘  └───────────────────┘  └┘        └─────────────────┘        └─┘
src    └─────────────────┘        └───────────────────┘                 └─────────────────┘           └─┘
typ    └─────────────────┘ └┘ └┘  └───────────────────┘  └┘        └─────────────────┘        └─┘
doc    └─────────────────┘        └───────────────────┘                  └─────────────────┘
588  
589  @[simp] lemma bundle_mfderiv_within_proj {p : tangent_bundle I M} :
id                                                 └────────────┘  
src                                                └────────────┘
typ                                                └────────────┘  
doc    └──┘                                        └────────────┘
590    (bundle_mfderiv_within I I' f s p).1 = f p.1 := rfl
id      └───────────────────┘  └┘             └─┘
src     └───────────────────┘                       └─┘
typ     └───────────────────┘  └┘             └─┘
doc     └───────────────────┘
591  
592  @[simp] lemma bundle_mfderiv_tangent_bundle_proj {p : tangent_bundle I M} :
id                                                         └────────────┘  
src                                                        └────────────┘
typ                                                        └────────────┘  
doc    └──┘                                                └────────────┘
593    tangent_bundle.proj I' M' (bundle_mfderiv I I' f p) = f (tangent_bundle.proj I M p) := rfl
id     └─────────────────┘ └┘ └┘  └────────────┘  └┘       └─────────────────┘        └─┘
src    └─────────────────┘        └────────────┘               └─────────────────┘           └─┘
typ    └─────────────────┘ └┘ └┘  └────────────┘  └┘       └─────────────────┘        └─┘
doc    └─────────────────┘        └────────────┘                └─────────────────┘
594  
595  @[simp] lemma bundle_mfderiv_proj {p : tangent_bundle I M} :
id                                          └────────────┘  
src                                         └────────────┘
typ                                         └────────────┘  
doc    └──┘                                 └────────────┘
596    (bundle_mfderiv I I' f p).1 = f p.1 := rfl
id      └────────────┘  └┘            └─┘
src     └────────────┘                     └─┘
typ     └────────────┘  └┘            └─┘
doc     └────────────┘
597  
598  omit Is I's
599  
600  /-! ### Congruence lemmas for derivatives on manifolds -/
601  
602  lemma has_mfderiv_within_at.congr_of_mem_nhds_within (h : has_mfderiv_within_at I I' f s x f')
id                                                             └───────────────────┘  └┘    └┘
src                                                            └───────────────────┘
typ                                                            └───────────────────┘  └┘    └┘
doc                                                            └───────────────────┘
603    (h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) : has_mfderiv_within_at I I' f₁ s x f' :=
id           └┘  └┘ └─────────┘   └┘            └┘        └───────────────────┘  └┘ └┘   └┘
src          └┘   └┘ └─────────┘                                   └───────────────────┘
typ          └┘  └┘ └─────────┘   └┘            └┘        └───────────────────┘  └┘ └┘   └┘
doc          └┘   └┘ └─────────┘                                     └───────────────────┘
604  begin
st   └─────
605    refine ⟨continuous_within_at.congr_of_mem_nhds_within h.1 h₁ hx, _⟩,
id             └───────────────────────────────────────────┘    └┘ └┘
src    └─────┘ └───────────────────────────────────────────┘ └─┘    └──┘
typ    └─────┘ └───────────────────────────────────────────┘└─┘└┘└┘└──┘
doc    └─────┘                                               └─┘    └──┘
txt    └─────┘                                               └─┘    └──┘
par    └─────┘                                               └─┘    └──┘
pid                                                         └─┘    └──┘
st   ────────────────────────────────────────────────────────────────────┘└─
606    apply has_fderiv_within_at.congr_of_mem_nhds_within h.2,
id           └───────────────────────────────────────────┘ 
src    └────┘└───────────────────────────────────────────┘ └┘
typ    └────┘└───────────────────────────────────────────┘└┘
doc    └────┘                                              └┘
txt    └────┘                                              └┘
par    └────┘                                              └┘
pid                                                       └┘
st   ────────────────────────────────────────────────────────┘└─
607    { have : (ext_chart_at I x).inv_fun ⁻¹' {y | f₁ y = f y} ∈
id                                         └─┘     └┘        
src      └─────┘               └────────┘└─┘└──┘     └┘
typ      └─────┘               └────────┘└─┘└──┘└┘  └┘
doc      └─────┘               └────────┘└─┘ └──┘      └┘ 
txt      └─────┘               └────────┘    └──┘      └┘ 
par      └─────┘               └────────┘    └──┘      └┘ 
pid      └───┘└┘               └────────┘    └──┘      └┘ 
st   ───┘└────────────────────────────────────────────────────────
608        nhds_within ((ext_chart_at I x).to_fun x) ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun) :=
id         └─────────┘                                 └──────────┘                   └───┘ └──────┘
src  ─────┘└─────────┘                └───────┘ └┘  └──────────┘  └────────┘    └───┘└──────┘└────
typ  ─────┘└─────────┘                └───────┘ └┘  └──────────┘ └────────┘   └───┘└──────┘└────
doc  ─────┘└─────────┘                └───────┘ └┘  └──────────┘  └────────┘     └───┘        └────
txt  ─────┘                           └───────┘ └┘                └────────┘                  └────
par  ─────┘                           └───────┘ └┘                └────────┘                  └────
pid  ─────┘                           └───────┘ └┘                └────────┘                  └───
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────
609        ext_chart_preimage_mem_nhds_within I x h₁,
id         └────────────────────────────────┘   └┘
src  ─────┘└────────────────────────────────┘  
typ  ─────┘└────────────────────────────────┘└┘
doc  ─────┘└────────────────────────────────┘  
txt  ─────┘                                    
par  ─────┘                                    
pid  ─────┘                                    
st   ──────────────────────────────────────────────┘└─
610      apply filter.mem_sets_of_superset this (λy, _),
id             └─────────────────────────┘ └──┘
src      └────┘└─────────────────────────┘      └───┘
typ      └────┘└─────────────────────────┘└──┘  └───┘
doc      └────┘                                 └───┘
txt      └────┘                                 └───┘
par      └────┘                                 └───┘
pid                                            └───┘
st   ─────────────────────────────────────────────────┘└─
611      simp [written_in_ext_chart_at, hx] {contextual := tt} },
id             └─────────────────────┘  └┘                 └┘
src      └────┘└─────────────────────┘└┘  └┘ └────────────┘└┘└┘
typ      └────┘└─────────────────────┘└┘└┘└┘ └────────────┘└┘└┘
doc      └────┘└─────────────────────┘└┘  └┘ └────────────┘  └┘
txt      └────┘                       └┘  └┘ └────────────┘  └┘
par      └────┘                       └┘  └┘ └────────────┘  └┘
pid                                 └┘   └────────────┘  
st   ─────────────────────────────────────────────────────────┘└┘
612    { simp [written_in_ext_chart_at, hx] },
id             └─────────────────────┘  └┘
src      └────┘└─────────────────────┘└┘  └┘
typ      └────┘└─────────────────────┘└┘└┘└┘
doc      └────┘└─────────────────────┘└┘  └┘
txt      └────┘                       └┘  └┘
par      └────┘                       └┘  └┘
pid                                 └┘  
st   ──────────────────────────────────────┘└──
613  end
st   ──┘
614  
615  lemma has_mfderiv_within_at.congr_mono (h : has_mfderiv_within_at I I' f s x f')
id                                               └───────────────────┘  └┘    └┘
src                                              └───────────────────┘
typ                                              └───────────────────┘  └┘    └┘
doc                                              └───────────────────┘
616    (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) :
id                 └┘            └┘              
src                                                      
typ                └┘            └┘              
617    has_mfderiv_within_at I I' f₁ t x f' :=
id     └───────────────────┘  └┘ └┘   └┘
src    └───────────────────┘
typ    └───────────────────┘  └┘ └┘   └┘
doc    └───────────────────┘
618  (h.mono h₁).congr_of_mem_nhds_within (filter.mem_inf_sets_of_right ht) hx
id    └───┘ └┘ └──────────────────────┘   └──────────────────────────┘ └┘  └┘
src    └───┘    └──────────────────────┘   └──────────────────────────┘
typ   └───┘ └┘ └──────────────────────┘   └──────────────────────────┘ └┘  └┘
619  
620  lemma has_mfderiv_at.congr_of_mem_nhds (h : has_mfderiv_at I I' f x f')
id                                               └────────────┘  └┘   └┘
src                                              └────────────┘
typ                                              └────────────┘  └┘   └┘
doc                                              └────────────┘
621    (h₁ : ∀ᶠ y in 𝓝 x, f₁ y = f y) : has_mfderiv_at I I' f₁ x f' :=
id           └┘  └┘   └┘        └────────────┘  └┘ └┘  └┘
src          └┘   └┘                 └────────────┘
typ          └┘  └┘   └┘        └────────────┘  └┘ └┘  └┘
doc          └┘   └┘                  └────────────┘
622  begin
st   └─────
623    erw ← has_mfderiv_within_at_univ at ⊢ h,
id           └────────────────────────┘
src    └────┘└────────────────────────┘└─────┘
typ    └────┘└────────────────────────┘└─────┘
doc    └────┘                          └─────┘
txt    └────┘                          └─────┘
par    └────┘                          └─────┘
pid       └─┘                          └─────┘
st   ────────────────────────────────────────┘└─
624    apply h.congr_of_mem_nhds_within _ (mem_of_nhds h₁ : _),
id           └────────────────────────┘    └─────────┘ └┘
src    └────┘└────────────────────────┘└─┘ └─────────┘  └───┘
typ    └────┘└────────────────────────┘└─┘ └─────────┘└┘└───┘
doc    └────┘                          └─┘              └───┘
txt    └────┘                          └─┘              └───┘
par    └────┘                          └─┘              └───┘
pid                                   └─┘              └───┘
st   ────────────────────────────────────────────────────────┘└─
625    rwa nhds_within_univ
id         └──────────────┘
src    └──┘└──────────────┘
typ    └──┘└──────────────┘
doc    └──┘                
txt    └──┘                
par    └──┘                
pid                       
st   ──────────────────────┘
626  end
st   └─┘
627  
628  include Is I's
629  
630  lemma mdifferentiable_within_at.congr_of_mem_nhds_within
631    (h : mdifferentiable_within_at I I' f s x) (h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y)
id          └───────────────────────┘  └┘           └┘  └┘ └─────────┘   └┘    
src         └───────────────────────┘                   └┘   └┘ └─────────┘          
typ         └───────────────────────┘  └┘           └┘  └┘ └─────────┘   └┘    
doc         └───────────────────────┘                   └┘   └┘ └─────────┘    
632    (hx : f₁ x = f x) : mdifferentiable_within_at I I' f₁ s x :=
id           └┘        └───────────────────────┘  └┘ └┘  
src                       └───────────────────────┘
typ          └┘        └───────────────────────┘  └┘ └┘  
doc                        └───────────────────────┘
633  (h.has_mfderiv_within_at.congr_of_mem_nhds_within h₁ hx).mdifferentiable_within_at
id    └────────────────────┘└───────────────────────┘ └┘ └┘ └───────────────────────┘
src    └────────────────────┘└───────────────────────┘       └───────────────────────┘
typ   └────────────────────┘└───────────────────────┘ └┘ └┘ └───────────────────────┘
634  
635  variables (I I')
636  lemma mdifferentiable_within_at_congr_of_mem_nhds_within
637    (h₁ : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) :
id           └┘  └┘ └─────────┘   └┘            └┘    
src          └┘   └┘ └─────────┘                           
typ          └┘  └┘ └─────────┘   └┘            └┘    
doc          └┘   └┘ └─────────┘    
638    mdifferentiable_within_at I I' f s x ↔ mdifferentiable_within_at I I' f₁ s x :=
id     └───────────────────────┘  └┘     └───────────────────────┘  └┘ └┘  
src    └───────────────────────┘             └───────────────────────┘
typ    └───────────────────────┘  └┘     └───────────────────────┘  └┘ └┘  
doc    └───────────────────────┘              └───────────────────────┘
639  begin
st   └─────
640    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
641    { assume h,
src      └──────┘
typ      └──────┘
doc      └──────┘
txt      └──────┘
par      └──────┘
pid      └──────┘
st   ───┘└──────┘└─
642      apply h.congr_of_mem_nhds_within h₁ hx },
id             └────────────────────────┘ └┘ └┘
src      └────┘└────────────────────────┘    
typ      └────┘└────────────────────────┘└┘└┘
doc      └────┘                              
txt      └────┘                              
par      └────┘                              
pid                                         
st   ──────────────────────────────────────────┘└┘
643    { assume h,
src      └──────┘
typ      └──────┘
doc      └──────┘
txt      └──────┘
par      └──────┘
pid      └──────┘
st   ───────────┘└─
644      apply h.congr_of_mem_nhds_within _ hx.symm,
id             └────────────────────────┘   └─────┘
src      └────┘└────────────────────────┘└─┘└─────┘
typ      └────┘└────────────────────────┘└─┘└─────┘
doc      └────┘                          └─┘
txt      └────┘                          └─┘
par      └────┘                          └─┘
pid                                     └─┘
st   ─────────────────────────────────────────────┘└─
645      apply h₁.mono,
src      └────┘
typ      └────┘
doc      └────┘
txt      └────┘
par      └────┘
pid           
st   ────────────────┘└─
646      intro y,
src      └─────┘
typ      └─────┘
doc      └─────┘
txt      └─────┘
par      └─────┘
pid           └┘
st   ──────────┘└─
647      apply eq.symm }
id             └─────┘
src      └────┘└─────┘
typ      └────┘└─────┘
doc      └────┘       
txt      └────┘       
par      └────┘       
pid                  
st   ─────────────────┘└─
648  end
st   ──┘
649  variables {I I'}
650  
651  lemma mdifferentiable_within_at.congr_mono (h : mdifferentiable_within_at I I' f s x)
id                                                   └───────────────────────┘  └┘   
src                                                  └───────────────────────┘
typ                                                  └───────────────────────┘  └┘   
doc                                                  └───────────────────────┘
652    (ht : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (h₁ : t ⊆ s) : mdifferentiable_within_at I I' f₁ t x :=
id                 └┘            └┘                  └───────────────────────┘  └┘ └┘  
src                                                            └───────────────────────┘
typ                └┘            └┘                  └───────────────────────┘  └┘ └┘  
doc                                                               └───────────────────────┘
653  (has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at ht hx h₁).mdifferentiable_within_at
id    └──────────────────────────────┘ └────────────────────┘ └┘ └┘ └┘ └───────────────────────┘
src   └──────────────────────────────┘  └────────────────────┘          └───────────────────────┘
typ   └──────────────────────────────┘ └────────────────────┘ └┘ └┘ └┘ └───────────────────────┘
654  
655  lemma mdifferentiable_within_at.congr (h : mdifferentiable_within_at I I' f s x)
id                                              └───────────────────────┘  └┘   
src                                             └───────────────────────┘
typ                                             └───────────────────────┘  └┘   
doc                                             └───────────────────────┘
656    (ht : ∀x ∈ s, f₁ x = f x) (hx : f₁ x = f x) : mdifferentiable_within_at I I' f₁ s x :=
id                 └┘            └┘        └───────────────────────┘  └┘ └┘  
src                                                └───────────────────────┘
typ                └┘            └┘        └───────────────────────┘  └┘ └┘  
doc                                                  └───────────────────────┘
657  (has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at ht hx (subset.refl _)).mdifferentiable_within_at
id    └──────────────────────────────┘ └────────────────────┘ └┘ └┘  └─────────┘    └───────────────────────┘
src   └──────────────────────────────┘  └────────────────────┘        └─────────┘    └───────────────────────┘
typ   └──────────────────────────────┘ └────────────────────┘ └┘ └┘  └─────────┘    └───────────────────────┘
658  
659  lemma mdifferentiable_on.congr_mono (h : mdifferentiable_on I I' f s) (h' : ∀x ∈ t, f₁ x = f x)
id                                            └────────────────┘  └┘                └┘    
src                                           └────────────────┘                              
typ                                           └────────────────┘  └┘                └┘    
doc                                           └────────────────┘
660    (h₁ : t ⊆ s) : mdifferentiable_on I I' f₁ t :=
id                 └────────────────┘  └┘ └┘ 
src                  └────────────────┘
typ                └────────────────┘  └┘ └┘ 
doc                   └────────────────┘
661  λ x hx, (h x (h₁ hx)).congr_mono h' (h' x hx) h₁
id      └┘      └┘ └┘  └────────┘  └┘  └┘  └┘  └┘
src                       └────────┘
typ     └┘      └┘ └┘  └────────┘  └┘  └┘  └┘  └┘
662  
663  lemma mdifferentiable_at.congr_of_mem_nhds (h : mdifferentiable_at I I' f x)
id                                                   └────────────────┘  └┘  
src                                                  └────────────────┘
typ                                                  └────────────────┘  └┘  
doc                                                  └────────────────┘
664    (hL : ∀ᶠ y in 𝓝 x, f₁ y = f y) : mdifferentiable_at I I' f₁ x :=
id           └┘  └┘   └┘        └────────────────┘  └┘ └┘ 
src          └┘   └┘                 └────────────────┘
typ          └┘  └┘   └┘        └────────────────┘  └┘ └┘ 
doc          └┘   └┘                  └────────────────┘
665  ((h.has_mfderiv_at).congr_of_mem_nhds hL).mdifferentiable_at
id     └─────────────┘ └───────────────┘  └┘ └────────────────┘
src     └─────────────┘ └───────────────┘     └────────────────┘
typ    └─────────────┘ └───────────────┘  └┘ └────────────────┘
666  
667  lemma mdifferentiable_within_at.mfderiv_within_congr_mono (h : mdifferentiable_within_at I I' f s x)
id                                                                  └───────────────────────┘  └┘   
src                                                                 └───────────────────────┘
typ                                                                 └───────────────────────┘  └┘   
doc                                                                 └───────────────────────┘
668    (hs : ∀x ∈ t, f₁ x = f x) (hx : f₁ x = f x) (hxt : unique_mdiff_within_at I t x) (h₁ : t ⊆ s) :
id                 └┘            └┘             └────────────────────┘             
src                                                     └────────────────────┘                
typ                └┘            └┘             └────────────────────┘             
doc                                                       └────────────────────┘
669    mfderiv_within I I' f₁ t x = (mfderiv_within I I' f s x : _) :=
id     └────────────┘  └┘ └┘     └────────────┘  └┘   
src    └────────────┘               └────────────┘
typ    └────────────┘  └┘ └┘     └────────────┘  └┘   
doc    └────────────┘                └────────────┘
670  (has_mfderiv_within_at.congr_mono h.has_mfderiv_within_at hs hx h₁).mfderiv_within hxt
id    └──────────────────────────────┘ └────────────────────┘ └┘ └┘ └┘ └────────────┘  └─┘
src   └──────────────────────────────┘  └────────────────────┘          └────────────┘
typ   └──────────────────────────────┘ └────────────────────┘ └┘ └┘ └┘ └────────────┘  └─┘
671  
672  lemma mfderiv_within_congr_of_mem_nhds_within (hs : unique_mdiff_within_at I s x)
id                                                       └────────────────────┘   
src                                                      └────────────────────┘
typ                                                      └────────────────────┘   
doc                                                      └────────────────────┘
673    (hL : ∀ᶠ y in nhds_within x s, f₁ y = f y) (hx : f₁ x = f x) :
id           └┘  └┘ └─────────┘   └┘            └┘    
src          └┘   └┘ └─────────┘                           
typ          └┘  └┘ └─────────┘   └┘            └┘    
doc          └┘   └┘ └─────────┘    
674    mfderiv_within I I' f₁ s x = (mfderiv_within I I' f s x : _) :=
id     └────────────┘  └┘ └┘     └────────────┘  └┘   
src    └────────────┘               └────────────┘
typ    └────────────┘  └┘ └┘     └────────────┘  └┘   
doc    └────────────┘                └────────────┘
675  begin
st   └─────
676    by_cases h : mdifferentiable_within_at I I' f s x,
id                  └───────────────────────┘  └┘   
src    └───────┘ └─┘└───────────────────────┘     
typ    └───────┘ └─┘└───────────────────────┘└┘
doc    └───────┘ └─┘└───────────────────────┘     
txt    └───────┘ └─┘                              
par    └───────┘ └─┘                              
pid             └─┘                              
st   ──────────────────────────────────────────────────┘└─
677    { exact ((h.has_mfderiv_within_at).congr_of_mem_nhds_within hL hx).mfderiv_within hs },
id               └─────────────────────┘                           └┘ └┘                 └┘
src      └────┘  └─────────────────────┘└─────────────────────────┘    └───────────────┘  
typ      └────┘  └─────────────────────┘└─────────────────────────┘└┘└┘└───────────────┘└┘
doc      └────┘                         └─────────────────────────┘    └───────────────┘  
txt      └────┘                         └─────────────────────────┘    └───────────────┘  
par      └────┘                         └─────────────────────────┘    └───────────────┘  
pid                                    └─────────────────────────┘    └───────────────┘  
st   ───┘└─────────────────────────────────────────────────────────────────────────────────┘└┘
678    { unfold mfderiv_within,
src      └───────────────────┘
typ      └───────────────────┘
doc      └───────────────────┘
txt      └───────────────────┘
par      └───────────────────┘
pid            └─────────────┘
st   ────────────────────────┘└─
679      rw [dif_neg, dif_neg],
id           └─────┘  └─────┘
src      └──┘└─────┘└┘└─────┘
typ      └──┘└─────┘└┘└─────┘
doc      └──┘       └┘       
txt      └──┘       └┘       
par      └──┘       └┘       
pid        └┘       └┘       
st   ──────────────┘└───────┘└──
680      assumption,
src      └────────┘
typ      └────────┘
doc      └────────┘
txt      └────────┘
par      └────────┘
st   ─────────────┘└─
681      rwa ← mdifferentiable_within_at_congr_of_mem_nhds_within I I' hL hx }
id             └────────────────────────────────────────────────┘  └┘ └┘ └┘
src      └────┘└────────────────────────────────────────────────┘       
typ      └────┘└────────────────────────────────────────────────┘└┘└┘└┘
doc      └────┘                                                         
txt      └────┘                                                         
par      └────┘                                                         
pid         └─┘                                                         
st   ───────────────────────────────────────────────────────────────────────┘└─
682  end
st   ──┘
683  
684  lemma mfderiv_congr_of_mem_nhds (hL : ∀ᶠ y in 𝓝 x, f₁ y = f y) :
id                                         └┘  └┘   └┘    
src                                        └┘   └┘         
typ                                        └┘  └┘   └┘    
doc                                        └┘   └┘   
685    mfderiv I I' f₁ x = (mfderiv I I' f x : _) :=
id     └─────┘  └┘ └┘    └─────┘  └┘  
src    └─────┘             └─────┘
typ    └─────┘  └┘ └┘    └─────┘  └┘  
doc    └─────┘              └─────┘
686  begin
st   └─────
687    have A : f₁ x = f x := (mem_of_nhds hL : _),
id              └┘          └─────────┘ └┘
src    └───────┘     └──┘ └─────────┘  └───┘
typ    └───────┘└┘ └──┘ └─────────┘└┘└───┘
doc    └───────┘      └──┘              └───┘
txt    └───────┘      └──┘              └───┘
par    └───────┘      └──┘              └───┘
pid    └────┘└─┘      └──┘              └───┘
st   ────────────────────────────────────────────┘└─
688    rw [← mfderiv_within_univ, ← mfderiv_within_univ],
id           └─────────────────┘    └─────────────────┘
src    └────┘└─────────────────┘└──┘└─────────────────┘
typ    └────┘└─────────────────┘└──┘└─────────────────┘
doc    └────┘                   └──┘                   
txt    └────┘                   └──┘                   
par    └────┘                   └──┘                   
pid      └──┘                   └──┘                   
st   ──────────────────────────┘└─────────────────────┘└──
689    rw ← nhds_within_univ at hL,
id          └──────────────┘
src    └───┘└──────────────┘└────┘
typ    └───┘└──────────────┘└────┘
doc    └───┘                └────┘
txt    └───┘                └────┘
par    └───┘                └────┘
pid      └─┘                └────┘
st   ────────────────────────────┘└─
690    exact mfderiv_within_congr_of_mem_nhds_within (unique_mdiff_within_at_univ I) hL A
id           └─────────────────────────────────────┘  └─────────────────────────┘   └┘ 
src    └────┘└─────────────────────────────────────┘ └─────────────────────────┘ └┘   
typ    └────┘└─────────────────────────────────────┘ └─────────────────────────┘└┘└┘
doc    └────┘                                                                    └┘   
txt    └────┘                                                                    └┘   
par    └────┘                                                                    └┘   
pid                                                                             └┘   
st   ────────────────────────────────────────────────────────────────────────────────────┘
691  end
st   └─┘
692  
693  /-! ### Composition lemmas -/
694  
695  omit Is I's
696  
697  lemma written_in_ext_chart_comp (h : continuous_within_at f s x) :
id                                        └──────────────────┘   
src                                       └──────────────────┘
typ                                       └──────────────────┘   
doc                                       └──────────────────┘
698    {y | written_in_ext_chart_at I I'' x (g ∘ f) y
id        └─────────────────────┘  └─┘       
src        └─────────────────────┘            
typ       └─────────────────────┘  └─┘       
doc         └─────────────────────┘
699         = ((written_in_ext_chart_at I' I'' (f x) g) ∘ (written_in_ext_chart_at I I' x f)) y}
id             └─────────────────────┘ └┘ └─┘         └─────────────────────┘  └┘     
src            └─────────────────────┘                   └─────────────────────┘
typ            └─────────────────────┘ └┘ └─┘         └─────────────────────┘  └┘     
doc             └─────────────────────┘                    └─────────────────────┘
700    ∈ nhds_within ((ext_chart_at I x).to_fun x) ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun) :=
id      └─────────┘   └──────────┘   └────┘      └──────────┘   └─────┘  └─┘   └───┘ └─────┘
src     └─────────┘   └──────────┘     └────┘       └──────────┘     └─────┘  └─┘    └───┘  └─────┘
typ     └─────────┘   └──────────┘   └────┘      └──────────┘   └─────┘  └─┘   └───┘ └─────┘
doc      └─────────┘   └──────────┘                  └──────────┘              └─┘     └───┘
701  begin
st   └─────
702    apply @filter.mem_sets_of_superset _ _
id            └─────────────────────────┘
src    └────┘ └─────────────────────────┘└────
typ    └────┘ └─────────────────────────┘└────
doc    └────┘                            └────
txt    └────┘                            └────
par    └────┘                            └────
pid                                     └────
st   ─────────────────────────────────────────
703      ((f ∘ (ext_chart_at I x).inv_fun)⁻¹' (ext_chart_at I' (f x)).source) _
id                                       └─┘  └──────────┘ └┘  
src  ───┘                  └────────┘└─┘ └──────────┘     └────────────
typ  ───┘                  └────────┘└─┘ └──────────┘└┘  └────────────
doc  ───┘                   └────────┘└─┘ └──────────┘     └────────────
txt  ───┘                   └────────┘                     └────────────
par  ───┘                   └────────┘                     └────────────
pid  ───┘                   └────────┘                     └────────────
st   ───────────────────────────────────────────────────────────────────────────
704      (ext_chart_preimage_mem_nhds_within I x (h.preimage_mem_nhds_within (ext_chart_at_source_mem_nhds _ _))),
id        └────────────────────────────────┘    └────────────────────────┘  └──────────────────────────┘
src  ───┘ └────────────────────────────────┘   └────────────────────────┘ └──────────────────────────┘└─────┘
typ  ───┘ └────────────────────────────────┘ └────────────────────────┘ └──────────────────────────┘└─────┘
doc  ───┘ └────────────────────────────────┘                                                          └─────┘
txt  ───┘                                                                                             └─────┘
par  ───┘                                                                                             └─────┘
pid  ───┘                                                                                             └─────┘
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
705    assume y hy,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid    └─────────┘
st   ────────────┘└─
706    simp only [ext_chart_at, written_in_ext_chart_at, model_with_corners_left_inv,
id                └──────────┘  └─────────────────────┘  └─────────────────────────┘
src    └─────────┘└──────────┘└┘└─────────────────────┘└┘└─────────────────────────┘└─
typ    └─────────┘└──────────┘└┘└─────────────────────┘└┘└─────────────────────────┘└─
doc    └─────────┘└──────────┘└┘└─────────────────────┘└┘                           └─
txt    └─────────┘            └┘                       └┘                           └─
par    └─────────┘            └┘                       └┘                           └─
pid        └──┘└┘            └┘                       └┘                           └─
st   ─────────────────────────────────────────────────────────────────────────────────
707               mem_set_of_eq, function.comp_app, local_equiv.trans_to_fun, local_equiv.trans_inv_fun],
id                └───────────┘  └───────────────┘  └──────────────────────┘  └───────────────────────┘
src  ────────────┘└───────────┘└┘└───────────────┘└┘└──────────────────────┘└┘└───────────────────────┘
typ  ────────────┘└───────────┘└┘└───────────────┘└┘└──────────────────────┘└┘└───────────────────────┘
doc  ────────────┘             └┘                 └┘                        └┘                         
txt  ────────────┘             └┘                 └┘                        └┘                         
par  ────────────┘             └┘                 └┘                        └┘                         
pid  ────────────┘             └┘                 └┘                        └┘                         
st   ──────────────────────────────────────────────────────────────────────────────────────────────────┘└─
708    rw (chart_at H' (f x)).left_inv,
id         └──────┘ └┘   
src    └─┘ └──────┘     └─────────┘
typ    └─┘ └──────┘└┘ └─────────┘
doc    └─┘              └─────────┘
txt    └─┘              └─────────┘
par    └─┘              └─────────┘
pid                    └────────┘
st   ────────────────────────────────┘└─
709    simpa [ext_chart_at_source] using hy
id            └─────────────────┘        └┘
src    └─────┘└─────────────────┘└──────┘  
typ    └─────┘└─────────────────┘└──────┘└┘
doc    └─────┘                   └──────┘  
txt    └─────┘                   └──────┘  
par    └─────┘                   └──────┘  
pid                            └────┘  
st   ──────────────────────────────────────┘
710  end
st   └─┘
711  
712  variable (x)
713  include Is I's I''s
714  
715  theorem has_mfderiv_within_at.comp
716    (hg : has_mfderiv_within_at I' I'' g u (f x) g') (hf : has_mfderiv_within_at I I' f s x f')
id           └───────────────────┘ └┘ └─┘       └┘        └───────────────────┘  └┘    └┘
src          └───────────────────┘                            └───────────────────┘
typ          └───────────────────┘ └┘ └─┘       └┘        └───────────────────┘  └┘    └┘
doc          └───────────────────┘                            └───────────────────┘
717    (hst : s ⊆ f ⁻¹' u) :
id               └─┘ 
src                └─┘
typ              └─┘ 
doc                 └─┘
718    has_mfderiv_within_at I I'' (g ∘ f) s x (g'.comp f') :=
id     └───────────────────┘  └─┘         └┘└───┘ └┘
src    └───────────────────┘                     └───┘
typ    └───────────────────┘  └─┘         └┘└───┘ └┘
doc    └───────────────────┘                      └───┘
719  begin
st   └─────
720    refine ⟨continuous_within_at.comp hg.1 hf.1 hst, _⟩,
id             └───────────────────────┘ └┘   └┘   └─┘
src    └─────┘ └───────────────────────┘  └─┘  └─┘   └──┘
typ    └─────┘ └───────────────────────┘└┘└─┘└┘└─┘└─┘└──┘
doc    └─────┘                            └─┘  └─┘   └──┘
txt    └─────┘                            └─┘  └─┘   └──┘
par    └─────┘                            └─┘  └─┘   └──┘
pid                                      └─┘  └─┘   └──┘
st   ────────────────────────────────────────────────────┘└─
721    have A : has_fderiv_within_at ((written_in_ext_chart_at I' I'' (f x) g) ∘
id              └──────────────────┘                              └─┘         
src    └───────┘└──────────────────┘                                 └┘ └┘
typ    └───────┘└──────────────────┘                           └─┘   └┘└┘
doc    └───────┘└──────────────────┘                                 └┘ └┘ 
txt    └───────┘                                                     └┘ └┘ 
par    └───────┘                                                     └┘ └┘ 
pid    └────┘└─┘                                                     └┘ └┘ 
st   ────────────────────────────────────────────────────────────────────────────
722         (written_in_ext_chart_at I I' x f))
id           └─────────────────────┘   └┘   
src  ──────┘ └─────────────────────┘     └──
typ  ──────┘ └─────────────────────┘ └┘ └──
doc  ──────┘ └─────────────────────┘     └──
txt  ──────┘                             └──
par  ──────┘                             └──
pid  ──────┘                             └──
st   ───────────────────────────────────────────
723      (continuous_linear_map.comp g' f' : E →L[𝕜] E'')
id        └────────────────────────┘ └┘ └┘    └─┘ └─┘
src  ───┘ └────────────────────────┘    └─┘ └─┘    └─
typ  ───┘ └────────────────────────┘└┘└┘└─┘└─┘└─┘└─
doc  ───┘ └────────────────────────┘    └─┘ └─┘    └─
txt  ───┘                               └─┘         └─
par  ───┘                               └─┘         └─
pid  ───┘                               └─┘         └─
st   ─────────────────────────────────────────────────────
724      ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range (I.to_fun))
id                                   └─┘   └───┘  └──────┘
src  ───┘                └────────┘└─┘ └───┘ └──────┘└──
typ  ───┘                └────────┘└─┘└───┘ └──────┘└──
doc  ───┘                └────────┘└─┘  └───┘         └──
txt  ───┘                └────────┘                   └──
par  ───┘                └────────┘                   └──
pid  ───┘                └────────┘                   └──
st   ──────────────────────────────────────────────────────────
725      ((ext_chart_at I x).to_fun x),
id         └──────────┘            
src  ───┘  └──────────┘  └───────┘ 
typ  ───┘  └──────────┘ └───────┘
doc  ───┘  └──────────┘  └───────┘ 
txt  ───┘                └───────┘ 
par  ───┘                └───────┘ 
pid  ───┘                └───────┘ 
st   ────────────────────────────────┘└─
726    { have : (ext_chart_at I x).inv_fun ⁻¹' (f ⁻¹' (ext_chart_at I' (f x)).source)
id                                                                  └┘  
src      └─────┘               └────────┘                          └──────────
typ      └─────┘               └────────┘                     └┘  └──────────
doc      └─────┘               └────────┘                          └──────────
txt      └─────┘               └────────┘                          └──────────
par      └─────┘               └────────┘                          └──────────
pid      └───┘└┘               └────────┘                          └──────────
st   ───┘└────────────────────────────────────────────────────────────────────────────
727      ∈ nhds_within ((ext_chart_at I x).to_fun x) ((ext_chart_at I x).inv_fun ⁻¹' s ∩ range I.to_fun) :=
id        └─────────┘                                 └──────────┘                    └───┘ └──────┘
src  ───┘└─────────┘                └───────┘ └┘  └──────────┘  └────────┘     └───┘└──────┘└────
typ  ───┘└─────────┘                └───────┘ └┘  └──────────┘ └────────┘    └───┘└──────┘└────
doc  ───┘ └─────────┘                └───────┘ └┘  └──────────┘  └────────┘     └───┘        └────
txt  ───┘                            └───────┘ └┘                └────────┘                  └────
par  ───┘                            └───────┘ └┘                └────────┘                  └────
pid  ───┘                            └───────┘ └┘                └────────┘                  └───
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────
728        (ext_chart_preimage_mem_nhds_within I x
id          └────────────────────────────────┘  
src  ─────┘ └────────────────────────────────┘  
typ  ─────┘ └────────────────────────────────┘
doc  ─────┘ └────────────────────────────────┘  
txt  ─────┘                                     
par  ─────┘                                     
pid  ─────┘                                     
st   ──────────────────────────────────────────────
729          (hf.1.preimage_mem_nhds_within (ext_chart_at_source_mem_nhds _ _))),
id            └┘                             └──────────────────────────┘
src  ───────┘   └──────────────────────────┘ └──────────────────────────┘└─────┘
typ  ───────┘ └┘└──────────────────────────┘ └──────────────────────────┘└─────┘
doc  ───────┘   └──────────────────────────┘                             └─────┘
txt  ───────┘   └──────────────────────────┘                             └─────┘
par  ───────┘   └──────────────────────────┘                             └─────┘
pid  ───────┘   └──────────────────────────┘                             └─────┘
st   ──────────────────────────────────────────────────────────────────────────┘└─
730      unfold has_mfderiv_within_at at *,
src      └───────────────────────────────┘
typ      └───────────────────────────────┘
doc      └───────────────────────────────┘
txt      └───────────────────────────────┘
par      └───────────────────────────────┘
pid            └────────────────────┘└───┘
st   ────────────────────────────────────┘└─
731      rw [← has_fderiv_within_at_inter' this, ← ext_chart_preimage_inter_eq] at hf ⊢,
id             └─────────────────────────┘ └──┘    └─────────────────────────┘
src      └────┘└─────────────────────────┘    └──┘└─────────────────────────┘└───────┘
typ      └────┘└─────────────────────────┘└──┘└──┘└─────────────────────────┘└───────┘
doc      └────┘                               └──┘└─────────────────────────┘└───────┘
txt      └────┘                               └──┘                           └───────┘
par      └────┘                               └──┘                           └───────┘
pid        └──┘                               └──┘                           └──────┘
st   ─────────────────────────────────────────┘└─────────────────────────────┘└──────┘└─
732      have : written_in_ext_chart_at I I' x f ((ext_chart_at I x).to_fun x)
id              └─────────────────────┘                         
src      └─────┘└─────────────────────┘                     └───────┘ └─
typ      └─────┘└─────────────────────┘                    └───────┘ └─
doc      └─────┘└─────────────────────┘                     └───────┘ └─
txt      └─────┘                                            └───────┘ └─
par      └─────┘                                            └───────┘ └─
pid      └───┘└┘                                            └───────┘ └─
st   ──────────────────────────────────────────────────────────────────────────
733          = (ext_chart_at I' (f x)).to_fun (f x),
id             └──────────┘ └┘                 
src  ───────┘ └──────────┘     └────────┘   
typ  ───────┘ └──────────┘└┘   └────────┘ 
doc  ───────┘  └──────────┘     └────────┘   
txt  ───────┘                   └────────┘   
par  ───────┘                   └────────┘   
pid  ───────┘                   └────────┘   
st   ─────────────────────────────────────────────┘
734        by simp [written_in_ext_chart_at, local_equiv.left_inv, mem_chart_source],
id                  └─────────────────────┘  └──────────────────┘  └──────────────┘
src           └────┘└─────────────────────┘└┘└──────────────────┘└┘└──────────────┘
typ           └────┘└─────────────────────┘└┘└──────────────────┘└┘└──────────────┘
doc           └────┘└─────────────────────┘└┘                    └┘                
txt           └────┘                       └┘                    └┘                
par           └────┘                       └┘                    └┘                
pid                                      └┘                    └┘                
st                                                                                  └─
735      rw ← this at hg,
id            └──┘
src      └───┘    └────┘
typ      └───┘└──┘└────┘
doc      └───┘    └────┘
txt      └───┘    └────┘
par      └───┘    └────┘
pid        └─┘    └────┘
st   ──────────────────┘└─
736      apply has_fderiv_within_at.comp ((ext_chart_at I x).to_fun x) hg.2 hf.2 _,
id             └───────────────────────┘   └──────────┘              └┘   └┘
src      └────┘└───────────────────────┘  └──────────┘  └───────┘ └┘  └─┘  └──┘
typ      └────┘└───────────────────────┘  └──────────┘ └───────┘└┘└┘└─┘└┘└──┘
doc      └────┘                           └──────────┘  └───────┘ └┘  └─┘  └──┘
txt      └────┘                                         └───────┘ └┘  └─┘  └──┘
par      └────┘                                         └───────┘ └┘  └─┘  └──┘
pid                                                    └───────┘ └┘  └─┘  └──┘
st   ────────────────────────────────────────────────────────────────────────────┘└─
737      assume y hy,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid      └─────────┘
st   ──────────────┘└─
738      simp [ext_chart_at, local_equiv.trans_source, -mem_range] at hy,
id             └──────────┘  └──────────────────────┘
src      └────┘└──────────┘└┘└──────────────────────┘└─────────────────┘
typ      └────┘└──────────┘└┘└──────────────────────┘└─────────────────┘
doc      └────┘└──────────┘└┘                        └─────────────────┘
txt      └────┘            └┘                        └─────────────────┘
par      └────┘            └┘                        └─────────────────┘
pid                      └┘                        └───────────┘└───┘
st   ──────────────────────────────────────────────────────────────────┘└─
739      have : f ((chart_at H x).inv_fun (I.inv_fun y)) ∈ u := hst hy.1.1,
id                 └──────┘             └───────┘          └─┘ └┘
src      └─────┘   └──────┘  └────────┘ └───────┘ └─┘  └──┘     └──┘
typ      └─────┘  └──────┘└────────┘ └───────┘└─┘ └──┘└─┘└┘└──┘
doc      └─────┘             └────────┘           └─┘  └──┘     └──┘
txt      └─────┘             └────────┘           └─┘  └──┘     └──┘
par      └─────┘             └────────┘           └─┘  └──┘     └──┘
pid      └───┘└┘             └────────┘           └─┘  └──┘     └┘└┘
st   ────────────────────────────────────────────────────────────────────┘└─
740      simp [written_in_ext_chart_at, ext_chart_at, -mem_range, hy, this, mem_range_self] },
id             └─────────────────────┘  └──────────┘              └┘  └──┘  └────────────┘
src      └────┘└─────────────────────┘└┘└──────────┘└────────────┘  └┘    └┘└────────────┘└┘
typ      └────┘└─────────────────────┘└┘└──────────┘└────────────┘└┘└┘└──┘└┘└────────────┘└┘
doc      └────┘└─────────────────────┘└┘└──────────┘└────────────┘  └┘    └┘              └┘
txt      └────┘                       └┘            └────────────┘  └┘    └┘              └┘
par      └────┘                       └┘            └────────────┘  └┘    └┘              └┘
pid                                 └┘            └────────────┘  └┘    └┘              
st   ──────────────────────────────────────────────────────────────────────────────────────┘└┘
741    apply A.congr_of_mem_nhds_within (written_in_ext_chart_comp hf.1),
id           └────────────────────────┘  └───────────────────────┘ └┘
src    └────┘└────────────────────────┘ └───────────────────────┘  └─┘
typ    └────┘└────────────────────────┘ └───────────────────────┘└┘└─┘
doc    └────┘                                                      └─┘
txt    └────┘                                                      └─┘
par    └────┘                                                      └─┘
pid                                                               └─┘
st   ──────────────────────────────────────────────────────────────────┘└─
742    simp [written_in_ext_chart_at, ext_chart_at, local_equiv.left_inv, mem_chart_source]
id           └─────────────────────┘  └──────────┘  └──────────────────┘  └──────────────┘
src    └────┘└─────────────────────┘└┘└──────────┘└┘└──────────────────┘└┘└──────────────┘└┘
typ    └────┘└─────────────────────┘└┘└──────────┘└┘└──────────────────┘└┘└──────────────┘└┘
doc    └────┘└─────────────────────┘└┘└──────────┘└┘                    └┘                └┘
txt    └────┘                       └┘            └┘                    └┘                └┘
par    └────┘                       └┘            └┘                    └┘                └┘
pid                               └┘            └┘                    └┘                
st   ──────────────────────────────────────────────────────────────────────────────────────┘
743  end
st   └─┘
744  
745  /-- The chain rule. -/
746  theorem has_mfderiv_at.comp
747    (hg : has_mfderiv_at I' I'' g (f x) g') (hf : has_mfderiv_at I I' f x f') :
id           └────────────┘ └┘ └─┘      └┘        └────────────┘  └┘   └┘
src          └────────────┘                          └────────────┘
typ          └────────────┘ └┘ └─┘      └┘        └────────────┘  └┘   └┘
doc          └────────────┘                          └────────────┘
748    has_mfderiv_at I I'' (g ∘ f) x (g'.comp f') :=
id     └────────────┘  └─┘        └┘└───┘ └┘
src    └────────────┘                   └───┘
typ    └────────────┘  └─┘        └┘└───┘ └┘
doc    └────────────┘                    └───┘
749  begin
st   └─────
750    rw ← has_mfderiv_within_at_univ at *,
id          └────────────────────────┘
src    └───┘└────────────────────────┘└───┘
typ    └───┘└────────────────────────┘└───┘
doc    └───┘                          └───┘
txt    └───┘                          └───┘
par    └───┘                          └───┘
pid      └─┘                          └───┘
st   ─────────────────────────────────────┘└─
751    exact has_mfderiv_within_at.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ
id           └────────────────────────┘   └─────┘  └─────────┘     └┘ └──────────────────┘
src    └────┘└────────────────────────┘  └─────┘ └─────────┘└───┘  └──────────────────┘
typ    └────┘└────────────────────────┘ └─────┘ └─────────┘└───┘└┘└──────────────────┘
doc    └────┘                                               └───┘                      
txt    └────┘                                               └───┘                      
par    └────┘                                               └───┘                      
pid                                                        └───┘                      
st   ──────────────────────────────────────────────────────────────────────────────────────┘
752  end
st   └─┘
753  
754  theorem has_mfderiv_at.comp_has_mfderiv_within_at
755    (hg : has_mfderiv_at I' I'' g (f x) g') (hf : has_mfderiv_within_at I I' f s x f') :
id           └────────────┘ └┘ └─┘      └┘        └───────────────────┘  └┘    └┘
src          └────────────┘                          └───────────────────┘
typ          └────────────┘ └┘ └─┘      └┘        └───────────────────┘  └┘    └┘
doc          └────────────┘                          └───────────────────┘
756    has_mfderiv_within_at I I'' (g ∘ f) s x (g'.comp f') :=
id     └───────────────────┘  └─┘         └┘└───┘ └┘
src    └───────────────────┘                     └───┘
typ    └───────────────────┘  └─┘         └┘└───┘ └┘
doc    └───────────────────┘                      └───┘
757  begin
st   └─────
758    rw ← has_mfderiv_within_at_univ at *,
id          └────────────────────────┘
src    └───┘└────────────────────────┘└───┘
typ    └───┘└────────────────────────┘└───┘
doc    └───┘                          └───┘
txt    └───┘                          └───┘
par    └───┘                          └───┘
pid      └─┘                          └───┘
st   ─────────────────────────────────────┘└─
759    exact has_mfderiv_within_at.comp x (hg.mono (subset_univ _)) hf subset_preimage_univ
id           └────────────────────────┘   └─────┘  └─────────┘     └┘ └──────────────────┘
src    └────┘└────────────────────────┘  └─────┘ └─────────┘└───┘  └──────────────────┘
typ    └────┘└────────────────────────┘ └─────┘ └─────────┘└───┘└┘└──────────────────┘
doc    └────┘                                               └───┘                      
txt    └────┘                                               └───┘                      
par    └────┘                                               └───┘                      
pid                                                        └───┘                      
st   ──────────────────────────────────────────────────────────────────────────────────────┘
760  end
st   └─┘
761  
762  lemma mdifferentiable_within_at.comp
763    (hg : mdifferentiable_within_at I' I'' g u (f x)) (hf : mdifferentiable_within_at I I' f s x)
id           └───────────────────────┘ └┘ └─┘              └───────────────────────┘  └┘   
src          └───────────────────────┘                         └───────────────────────┘
typ          └───────────────────────┘ └┘ └─┘              └───────────────────────┘  └┘   
doc          └───────────────────────┘                         └───────────────────────┘
764    (h : s ⊆ f ⁻¹' u) : mdifferentiable_within_at I I'' (g ∘ f) s x :=
id             └─┘     └───────────────────────┘  └─┘       
src              └─┘      └───────────────────────┘          
typ            └─┘     └───────────────────────┘  └─┘       
doc               └─┘      └───────────────────────┘
765  begin
st   └─────
766    rcases hf.2 with ⟨f', hf'⟩,
id            └┘
src    └─────┘  └───────────────┘
typ    └─────┘└┘└───────────────┘
doc    └─────┘  └───────────────┘
txt    └─────┘  └───────────────┘
par    └─────┘  └───────────────┘
pid            └───────────────┘
st   ───────────────────────────┘└─
767    have F : has_mfderiv_within_at I I' f s x f' := ⟨hf.1, hf'⟩,
id              └───────────────────┘  └┘    └┘     └┘    └─┘
src    └───────┘└───────────────────┘        └──┘   └──┘   
typ    └───────┘└───────────────────┘└┘└┘└──┘ └┘└──┘└─┘
doc    └───────┘└───────────────────┘        └──┘   └──┘   
txt    └───────┘                             └──┘   └──┘   
par    └───────┘                             └──┘   └──┘   
pid    └────┘└─┘                             └──┘   └──┘   
st   ────────────────────────────────────────────────────────────┘└─
768    rcases hg.2 with ⟨g', hg'⟩,
id            └┘
src    └─────┘  └───────────────┘
typ    └─────┘└┘└───────────────┘
doc    └─────┘  └───────────────┘
txt    └─────┘  └───────────────┘
par    └─────┘  └───────────────┘
pid            └───────────────┘
st   ───────────────────────────┘└─
769    have G : has_mfderiv_within_at I' I'' g u (f x) g' := ⟨hg.1, hg'⟩,
id              └───────────────────┘ └┘ └─┘       └┘     └┘    └─┘
src    └───────┘└───────────────────┘          └┘  └──┘   └──┘   
typ    └───────┘└───────────────────┘└┘└─┘ └┘└┘└──┘ └┘└──┘└─┘
doc    └───────┘└───────────────────┘          └┘  └──┘   └──┘   
txt    └───────┘                               └┘  └──┘   └──┘   
par    └───────┘                               └┘  └──┘   └──┘   
pid    └────┘└─┘                               └┘  └──┘   └──┘   
st   ──────────────────────────────────────────────────────────────────┘└─
770    exact (has_mfderiv_within_at.comp x G F h).mdifferentiable_within_at
id            └────────────────────────┘    
src    └────┘ └────────────────────────┘    └──────────────────────────┘
typ    └────┘ └────────────────────────┘└──────────────────────────┘
doc    └────┘                               └──────────────────────────┘
txt    └────┘                               └──────────────────────────┘
par    └────┘                               └──────────────────────────┘
pid                                        └────────────────────────┘└┘
st   ──────────────────────────────────────────────────────────────────────┘
771  end
st   └─┘
772  
773  lemma mdifferentiable_at.comp
774    (hg : mdifferentiable_at I' I'' g (f x)) (hf : mdifferentiable_at I I' f x) :
id           └────────────────┘ └┘ └─┘             └────────────────┘  └┘  
src          └────────────────┘                       └────────────────┘
typ          └────────────────┘ └┘ └─┘             └────────────────┘  └┘  
doc          └────────────────┘                       └────────────────┘
775    mdifferentiable_at I I'' (g ∘ f) x :=
id     └────────────────┘  └─┘      
src    └────────────────┘          
typ    └────────────────┘  └─┘      
doc    └────────────────┘
776  (hg.has_mfderiv_at.comp x hf.has_mfderiv_at).mdifferentiable_at
id    └┘└─────────────┘└───┘  └┘└─────────────┘ └────────────────┘
src     └─────────────┘└───┘     └─────────────┘ └────────────────┘
typ   └┘└─────────────┘└───┘  └┘└─────────────┘ └────────────────┘
doc                    └───┘
777  
778  lemma mfderiv_within_comp
779    (hg : mdifferentiable_within_at I' I'' g u (f x)) (hf : mdifferentiable_within_at I I' f s x)
id           └───────────────────────┘ └┘ └─┘              └───────────────────────┘  └┘   
src          └───────────────────────┘                         └───────────────────────┘
typ          └───────────────────────┘ └┘ └─┘              └───────────────────────┘  └┘   
doc          └───────────────────────┘                         └───────────────────────┘
780    (h : s ⊆ f ⁻¹' u) (hxs : unique_mdiff_within_at I s x) :
id             └─┘          └────────────────────┘   
src              └─┘           └────────────────────┘
typ            └─┘          └────────────────────┘   
doc               └─┘           └────────────────────┘
781    mfderiv_within I I'' (g ∘ f) s x = (mfderiv_within I' I'' g u (f x)).comp (mfderiv_within I I' f s x) :=
id     └────────────┘  └─┘          └────────────┘ └┘ └─┘       └──┘   └────────────┘  └┘   
src    └────────────┘                    └────────────┘                  └──┘   └────────────┘
typ    └────────────┘  └─┘          └────────────┘ └┘ └─┘       └──┘   └────────────┘  └┘   
doc    └────────────┘                      └────────────┘                  └──┘   └────────────┘
782  begin
st   └─────
783    apply has_mfderiv_within_at.mfderiv_within _ hxs,
id           └──────────────────────────────────┘   └─┘
src    └────┘└──────────────────────────────────┘└─┘
typ    └────┘└──────────────────────────────────┘└─┘└─┘
doc    └────┘                                    └─┘
txt    └────┘                                    └─┘
par    └────┘                                    └─┘
pid                                             └─┘
st   ─────────────────────────────────────────────────┘└─
784    exact has_mfderiv_within_at.comp x hg.has_mfderiv_within_at hf.has_mfderiv_within_at h
id           └────────────────────────┘  └──────────────────────┘ └──────────────────────┘ 
src    └────┘└────────────────────────┘ └──────────────────────┘└──────────────────────┘ 
typ    └────┘└────────────────────────┘└──────────────────────┘└──────────────────────┘
doc    └────┘                                                                            
txt    └────┘                                                                            
par    └────┘                                                                            
pid                                                                                     
st   ────────────────────────────────────────────────────────────────────────────────────────┘
785  end
st   └─┘
786  
787  lemma mfderiv_comp
788    (hg : mdifferentiable_at I' I'' g (f x)) (hf : mdifferentiable_at I I' f x) :
id           └────────────────┘ └┘ └─┘             └────────────────┘  └┘  
src          └────────────────┘                       └────────────────┘
typ          └────────────────┘ └┘ └─┘             └────────────────┘  └┘  
doc          └────────────────┘                       └────────────────┘
789    mfderiv I I'' (g ∘ f) x = (mfderiv I' I'' g (f x)).comp (mfderiv I I' f x) :=
id     └─────┘  └─┘         └─────┘ └┘ └─┘      └──┘   └─────┘  └┘  
src    └─────┘                  └─────┘                └──┘   └─────┘
typ    └─────┘  └─┘         └─────┘ └┘ └─┘      └──┘   └─────┘  └┘  
doc    └─────┘                    └─────┘                └──┘   └─────┘
790  begin
st   └─────
791    apply has_mfderiv_at.mfderiv,
id           └────────────────────┘
src    └────┘└────────────────────┘
typ    └────┘└────────────────────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ─────────────────────────────┘└─
792    exact has_mfderiv_at.comp x hg.has_mfderiv_at hf.has_mfderiv_at
id           └─────────────────┘  └───────────────┘ └───────────────┘
src    └────┘└─────────────────┘ └───────────────┘└───────────────┘
typ    └────┘└─────────────────┘└───────────────┘└───────────────┘
doc    └────┘└─────────────────┘                                   
txt    └────┘                                                      
par    └────┘                                                      
pid                                                               
st   ─────────────────────────────────────────────────────────────────┘
793  end
st   └─┘
794  
795  lemma mdifferentiable_on.comp
796    (hg : mdifferentiable_on I' I'' g u) (hf : mdifferentiable_on I I' f s) (st : s ⊆ f ⁻¹' u) :
id           └────────────────┘ └┘ └─┘          └────────────────┘  └┘             └─┘ 
src          └────────────────┘                   └────────────────┘                      └─┘
typ          └────────────────┘ └┘ └─┘          └────────────────┘  └┘             └─┘ 
doc          └────────────────┘                   └────────────────┘                       └─┘
797    mdifferentiable_on I I'' (g ∘ f) s :=
id     └────────────────┘  └─┘      
src    └────────────────┘          
typ    └────────────────┘  └─┘      
doc    └────────────────┘
798  λx hx, mdifferentiable_within_at.comp x (hg (f x) (st hx)) (hf x hx) st
id     └┘  └────────────────────────────┘   └┘      └┘ └┘    └┘  └┘  └┘
src         └────────────────────────────┘
typ    └┘  └────────────────────────────┘   └┘      └┘ └┘    └┘  └┘  └┘
799  
800  lemma mdifferentiable.comp
801    (hg : mdifferentiable I' I'' g) (hf : mdifferentiable I I' f) : mdifferentiable I I'' (g ∘ f) :=
id           └─────────────┘ └┘ └─┘         └─────────────┘  └┘     └─────────────┘  └─┘    
src          └─────────────┘                 └─────────────┘           └─────────────┘          
typ          └─────────────┘ └┘ └─┘         └─────────────┘  └┘     └─────────────┘  └─┘    
doc          └─────────────┘                 └─────────────┘           └─────────────┘
802  λx, mdifferentiable_at.comp x (hg (f x)) (hf x)
id      └─────────────────────┘   └┘       └┘ 
src      └─────────────────────┘
typ     └─────────────────────┘   └┘       └┘ 
803  
804  lemma bundle_mfderiv_within_comp_at (p : tangent_bundle I M)
id                                            └────────────┘  
src                                           └────────────┘
typ                                           └────────────┘  
doc                                           └────────────┘
805    (hg : mdifferentiable_within_at I' I'' g u (f p.1)) (hf : mdifferentiable_within_at I I' f s p.1)
id           └───────────────────────┘ └┘ └─┘               └───────────────────────┘  └┘   
src          └───────────────────────┘                          └───────────────────────┘           
typ          └───────────────────────┘ └┘ └─┘               └───────────────────────┘  └┘   
doc          └───────────────────────┘                           └───────────────────────┘
806    (h : s ⊆ f ⁻¹' u)  (hps : unique_mdiff_within_at I s p.1) :
id             └─┘           └────────────────────┘   
src              └─┘            └────────────────────┘      
typ            └─┘           └────────────────────┘   
doc               └─┘            └────────────────────┘
807    bundle_mfderiv_within I I'' (g ∘ f) s p =
id     └───────────────────┘  └─┘        
src    └───────────────────┘                  
typ    └───────────────────┘  └─┘        
doc    └───────────────────┘
808    bundle_mfderiv_within I' I'' g u (bundle_mfderiv_within I I' f s p) :=
id     └───────────────────┘ └┘ └─┘    └───────────────────┘  └┘   
src    └───────────────────┘             └───────────────────┘
typ    └───────────────────┘ └┘ └─┘    └───────────────────┘  └┘   
doc    └───────────────────┘             └───────────────────┘
809  begin
st   └─────
810    simp [bundle_mfderiv_within],
id           └───────────────────┘
src    └────┘└───────────────────┘
typ    └────┘└───────────────────┘
doc    └────┘└───────────────────┘
txt    └────┘                     
par    └────┘                     
pid                             
st   ─────────────────────────────┘└─
811    rw mfderiv_within_comp p.1 hg hf h hps,
id        └─────────────────┘    └┘ └┘  └─┘
src    └─┘└─────────────────┘ └─┘     
typ    └─┘└─────────────────┘└─┘└┘└┘└─┘
doc    └─┘                    └─┘     
txt    └─┘                    └─┘     
par    └─┘                    └─┘     
pid                          └─┘     
st   ───────────────────────────────────────┘└─
812    refl
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
pid        
st   ──────┘
813  end
st   └─┘
814  
815  lemma bundle_mfderiv_comp_at (p : tangent_bundle I M)
id                                     └────────────┘  
src                                    └────────────┘
typ                                    └────────────┘  
doc                                    └────────────┘
816    (hg : mdifferentiable_at I' I'' g (f p.1)) (hf : mdifferentiable_at I I' f p.1) :
id           └────────────────┘ └┘ └─┘              └────────────────┘  └┘  
src          └────────────────┘                        └────────────────┘         
typ          └────────────────┘ └┘ └─┘              └────────────────┘  └┘  
doc          └────────────────┘                         └────────────────┘
817    bundle_mfderiv I I'' (g ∘ f) p = bundle_mfderiv I' I'' g (bundle_mfderiv I I' f p) :=
id     └────────────┘  └─┘        └────────────┘ └┘ └─┘   └────────────┘  └┘  
src    └────────────┘                 └────────────┘           └────────────┘
typ    └────────────┘  └─┘        └────────────┘ └┘ └─┘   └────────────┘  └┘  
doc    └────────────┘                   └────────────┘           └────────────┘
818  begin
st   └─────
819    rcases p with ⟨x, v⟩,
id            
src    └─────┘ └──────────┘
typ    └─────┘└──────────┘
doc    └─────┘ └──────────┘
txt    └─────┘ └──────────┘
par    └─────┘ └──────────┘
pid           └──────────┘
st   ─────────────────────┘└─
820    simp [bundle_mfderiv],
id           └────────────┘
src    └────┘└────────────┘
typ    └────┘└────────────┘
doc    └────┘└────────────┘
txt    └────┘              
par    └────┘              
pid                      
st   ──────────────────────┘└─
821    rw mfderiv_comp x hg hf,
id        └──────────┘  └┘ └┘
src    └─┘└──────────┘   
typ    └─┘└──────────┘└┘└┘
doc    └─┘               
txt    └─┘               
par    └─┘               
pid                     
st   ────────────────────────┘└─
822    refl
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
pid        
st   ──────┘
823  end
st   └─┘
824  
825  lemma bundle_mfderiv_comp (hg : mdifferentiable I' I'' g) (hf : mdifferentiable I I' f) :
id                                   └─────────────┘ └┘ └─┘         └─────────────┘  └┘ 
src                                  └─────────────┘                 └─────────────┘
typ                                  └─────────────┘ └┘ └─┘         └─────────────┘  └┘ 
doc                                  └─────────────┘                 └─────────────┘
826    bundle_mfderiv I I'' (g ∘ f) = (bundle_mfderiv I' I'' g) ∘ (bundle_mfderiv I I' f) :=
id     └────────────┘  └─┘        └────────────┘ └┘ └─┘     └────────────┘  └┘ 
src    └────────────┘                └────────────┘             └────────────┘
typ    └────────────┘  └─┘        └────────────┘ └┘ └─┘     └────────────┘  └┘ 
doc    └────────────┘                  └────────────┘              └────────────┘
827  by { ext p : 1, exact bundle_mfderiv_comp_at _ (hg _) (hf _) }
id                         └────────────────────┘    └┘     └┘
src       └───────┘  └────┘└────────────────────┘└─┘   └──┘   └──┘
typ       └───────┘  └────┘└────────────────────┘└─┘ └┘└──┘ └┘└──┘
doc       └───────┘  └────┘                      └─┘   └──┘   └──┘
txt       └───────┘  └────┘                      └─┘   └──┘   └──┘
par       └───────┘  └────┘                      └─┘   └──┘   └──┘
pid          └┘└─┘                             └─┘   └──┘   └─┘
st     └──────────┘└─────────────────────────────────────────────┘└┘
828  
829  end derivatives_properties
830  
831  section specific_functions
832  
833  /-! ### Differentiability of specific functions -/
834  
835  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                         └──────────────────────┘
src                         └──────────────────────┘
typ                        └──────────────────────┘
doc                         └──────────────────────┘
836  {E : Type*} [normed_group E] [normed_space 𝕜 E]
id                └──────────┘     └──────────┘
src               └──────────┘     └──────────┘
typ               └──────────┘     └──────────┘
doc               └──────────┘     └──────────┘
837  {H : Type*} [topological_space H] (I : model_with_corners 𝕜 E H)
id                └───────────────┘         └────────────────┘
src               └───────────────┘         └────────────────┘
typ               └───────────────┘         └────────────────┘
doc               └───────────────┘         └────────────────┘
838  {M : Type*} [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
id                └───────────────┘     └──────┘       └──────────────────────────┘
src               └───────────────┘     └──────┘       └──────────────────────────┘
typ               └───────────────┘     └──────┘       └──────────────────────────┘
doc               └───────────────┘     └──────┘       └──────────────────────────┘
839  {s : set M} {x : M}
id        └─┘
src       └─┘
typ       └─┘
840  
841  section id
842  /-! #### Identity -/
843  
844  lemma has_mfderiv_at_id (x : M) :
id                                
typ                               
845    has_mfderiv_at I I (@_root_.id M) x
id     └────────────┘     └───────┘   
src    └────────────┘       └───────┘
typ    └────────────┘     └───────┘   
doc    └────────────┘
846    (continuous_linear_map.id : tangent_space I x →L[𝕜] tangent_space I x) :=
id      └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
src     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
doc     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
847  begin
st   └─────
848    refine ⟨continuous_id.continuous_at, _⟩,
id             └─────────────────────────┘
src    └─────┘ └─────────────────────────┘└──┘
typ    └─────┘ └─────────────────────────┘└──┘
doc    └─────┘                            └──┘
txt    └─────┘                            └──┘
par    └─────┘                            └──┘
pid                                      └──┘
st   ────────────────────────────────────────┘└─
849    have : ∀ᶠ y in nhds_within ((ext_chart_at I x).to_fun x) (range (I.to_fun)),
id            └┘   └┘ └─────────┘   └──────────┘                └───┘  └──────┘  
src    └─────┘└┘└─┘└┘└─────────┘  └──────────┘  └───────┘ └┘ └───┘ └──────┘└┘
typ    └─────┘└┘└─┘└┘└─────────┘  └──────────┘  └───────┘└┘ └───┘ └──────┘└┘
doc    └─────┘└┘└─┘└┘└─────────┘  └──────────┘  └───────┘ └┘ └───┘         └┘
txt    └─────┘  └─┘                             └───────┘ └┘               └┘ 
par    └─────┘  └─┘                             └───────┘ └┘               └┘ 
pid    └───┘└┘  └─┘                             └───────┘ └┘               └┘ 
st   ───────────────────────────────────────────────────────────────────────────────
850      ((ext_chart_at I x).to_fun ∘ (ext_chart_at I x).inv_fun) y = id y,
id                                                                  └┘
src  ───┘                └───────┘               └─────────┘ └┘
typ  ───┘                └───────┘               └─────────┘ └┘
doc  ───┘                └───────┘                └─────────┘    
txt  ───┘                └───────┘                └─────────┘    
par  ───┘                └───────┘                └─────────┘    
pid  ───┘                └───────┘                └─────────┘    
st   ────────────────────────────────────────────────────────────────────┘└─
851    { apply filter.mem_sets_of_superset (ext_chart_at_target_mem_nhds_within I x),
id             └─────────────────────────┘  └─────────────────────────────────┘  
src      └────┘└─────────────────────────┘ └─────────────────────────────────┘  
typ      └────┘└─────────────────────────┘ └─────────────────────────────────┘
doc      └────┘                                                                 
txt      └────┘                                                                 
par      └────┘                                                                 
pid                                                                            
st   ───┘└─────────────────────────────────────────────────────────────────────────┘└─
852      assume y hy,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid      └─────────┘
st   ──────────────┘└─
853      simp [(ext_chart_at I x).right_inv hy] },
id              └──────────┘              └┘
src      └────┘ └──────────┘  └──────────┘  └┘
typ      └────┘ └──────────┘└──────────┘└┘└┘
doc      └────┘ └──────────┘  └──────────┘  └┘
txt      └────┘               └──────────┘  └┘
par      └────┘               └──────────┘  └┘
pid                         └──────────┘  
st   ──────────────────────────────────────────┘└┘
854    apply has_fderiv_within_at.congr_of_mem_nhds_within (has_fderiv_within_at_id _ _) this,
id           └───────────────────────────────────────────┘  └─────────────────────┘      └──┘
src    └────┘└───────────────────────────────────────────┘ └─────────────────────┘└────┘
typ    └────┘└───────────────────────────────────────────┘ └─────────────────────┘└────┘└──┘
doc    └────┘                                                                     └────┘
txt    └────┘                                                                     └────┘
par    └────┘                                                                     └────┘
pid                                                                              └────┘
st   ───────────────────────────────────────────────────────────────────────────────────────┘└─
855    simp [(ext_chart_at I x).left_inv, mem_ext_chart_source I x]
id            └──────────┘              └──────────────────┘  
src    └────┘ └──────────┘  └──────────┘└──────────────────┘  └┘
typ    └────┘ └──────────┘└──────────┘└──────────────────┘└┘
doc    └────┘ └──────────┘  └──────────┘                      └┘
txt    └────┘               └──────────┘                      └┘
par    └────┘               └──────────┘                      └┘
pid                       └──────────┘                      
st   ──────────────────────────────────────────────────────────────┘
856  end
st   └─┘
857  
858  theorem has_mfderiv_within_at_id (s : set M) (x : M) :
id                                         └─┘        
src                                        └─┘
typ                                        └─┘        
859    has_mfderiv_within_at I I (@_root_.id M) s x
id     └───────────────────┘     └───────┘    
src    └───────────────────┘       └───────┘
typ    └───────────────────┘     └───────┘    
doc    └───────────────────┘
860    (continuous_linear_map.id : tangent_space I x →L[𝕜] tangent_space I x) :=
id      └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
src     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
doc     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
861  (has_mfderiv_at_id I x).has_mfderiv_within_at
id    └───────────────┘   └───────────────────┘
src   └───────────────┘     └───────────────────┘
typ   └───────────────┘   └───────────────────┘
862  
863  lemma mdifferentiable_at_id : mdifferentiable_at I I (@_root_.id M) x :=
id                                 └────────────────┘     └───────┘   
src                                └────────────────┘       └───────┘
typ                                └────────────────┘     └───────┘   
doc                                └────────────────┘
864  (has_mfderiv_at_id I x).mdifferentiable_at
id    └───────────────┘   └────────────────┘
src   └───────────────┘     └────────────────┘
typ   └───────────────┘   └────────────────┘
865  
866  lemma mdifferentiable_within_at_id : mdifferentiable_within_at I I (@_root_.id M) s x :=
id                                        └───────────────────────┘     └───────┘    
src                                       └───────────────────────┘       └───────┘
typ                                       └───────────────────────┘     └───────┘    
doc                                       └───────────────────────┘
867  (mdifferentiable_at_id I).mdifferentiable_within_at
id    └───────────────────┘  └───────────────────────┘
src   └───────────────────┘   └───────────────────────┘
typ   └───────────────────┘  └───────────────────────┘
868  
869  lemma mdifferentiable_id : mdifferentiable I I (@_root_.id M) :=
id                              └─────────────┘     └───────┘ 
src                             └─────────────┘       └───────┘
typ                             └─────────────┘     └───────┘ 
doc                             └─────────────┘
870  λx, mdifferentiable_at_id I
id      └───────────────────┘ 
src      └───────────────────┘
typ     └───────────────────┘ 
871  
872  lemma mdifferentiable_on_id : mdifferentiable_on I I (@_root_.id M) s :=
id                                 └────────────────┘     └───────┘   
src                                └────────────────┘       └───────┘
typ                                └────────────────┘     └───────┘   
doc                                └────────────────┘
873  (mdifferentiable_id I).mdifferentiable_on
id    └────────────────┘  └────────────────┘
src   └────────────────┘   └────────────────┘
typ   └────────────────┘  └────────────────┘
874  
875  @[simp] lemma mfderiv_id : mfderiv I I (@_root_.id M) x =
id                              └─────┘     └───────┘    
src                             └─────┘       └───────┘      
typ                             └─────┘     └───────┘    
doc    └──┘                     └─────┘
876    (continuous_linear_map.id : tangent_space I x →L[𝕜] tangent_space I x) :=
id      └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
src     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
doc     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
877  has_mfderiv_at.mfderiv (has_mfderiv_at_id I x)
id   └────────────────────┘  └───────────────┘  
src  └────────────────────┘  └───────────────┘
typ  └────────────────────┘  └───────────────┘  
878  
879  lemma mfderiv_within_id (hxs : unique_mdiff_within_at I s x) :
id                                  └────────────────────┘   
src                                 └────────────────────┘
typ                                 └────────────────────┘   
doc                                 └────────────────────┘
880    mfderiv_within I I (@_root_.id M) s x =
id     └────────────┘     └───────┘     
src    └────────────┘       └───────┘        
typ    └────────────┘     └───────┘     
doc    └────────────┘
881    (continuous_linear_map.id : tangent_space I x →L[𝕜] tangent_space I x) :=
id      └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
src     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └──────────────────────┘   └───────────┘   └─┘ └───────────┘  
doc     └──────────────────────┘   └───────────┘     └─┘  └───────────┘
882  begin
st   └─────
883    rw mdifferentiable.mfderiv_within (mdifferentiable_at_id I) hxs,
id        └────────────────────────────┘  └───────────────────┘   └─┘
src    └─┘└────────────────────────────┘ └───────────────────┘ └┘
typ    └─┘└────────────────────────────┘ └───────────────────┘└┘└─┘
doc    └─┘                                                     └┘
txt    └─┘                                                     └┘
par    └─┘                                                     └┘
pid                                                           └┘
st   ────────────────────────────────────────────────────────────────┘└─
884    exact mfderiv_id I
id           └────────┘ 
src    └────┘└────────┘ 
typ    └────┘└────────┘
doc    └────┘           
txt    └────┘           
par    └────┘           
pid                    
st   ────────────────────┘
885  end
st   └─┘
886  
887  end id
888  
889  section const
890  /-! #### Constants -/
891  
892  variables {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
id                           └──────────┘      └──────────┘
src                          └──────────┘      └──────────┘
typ                          └──────────┘      └──────────┘
doc                          └──────────┘      └──────────┘
893  {H' : Type*} [topological_space H'] (I' : model_with_corners 𝕜 E' H')
id                 └───────────────┘           └────────────────┘
src                └───────────────┘           └────────────────┘
typ                └───────────────┘           └────────────────┘
doc                └───────────────┘           └────────────────┘
894  {M' : Type*} [topological_space M'] [manifold H' M'] [smooth_manifold_with_corners I' M']
id                 └───────────────┘      └──────┘         └──────────────────────────┘
src                └───────────────┘      └──────┘         └──────────────────────────┘
typ                └───────────────┘      └──────┘         └──────────────────────────┘
doc                └───────────────┘      └──────┘         └──────────────────────────┘
895  {c : M'}
896  
897  lemma has_mfderiv_at_const (c : M') (x : M) :
id                                   └┘       
typ                                  └┘       
898    has_mfderiv_at I I' (λy : M, c) x
id     └────────────┘  └┘           
src    └────────────┘
typ    └────────────┘  └┘           
doc    └────────────┘
899    (continuous_linear_map.zero : tangent_space I x →L[𝕜] tangent_space I' c) :=
id      └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
src     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
doc     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
900  begin
st   └─────
901    refine ⟨continuous_const.continuous_at, _⟩,
id             └────────────────────────────┘
src    └─────┘ └────────────────────────────┘└──┘
typ    └─────┘ └────────────────────────────┘└──┘
doc    └─────┘                               └──┘
txt    └─────┘                               └──┘
par    └─────┘                               └──┘
pid                                         └──┘
st   ───────────────────────────────────────────┘└─
902    have : (ext_chart_at I' c).to_fun ∘ (λ (y : M), c) ∘ (ext_chart_at I x).inv_fun =
id                                                                                 
src    └─────┘                └───────┘  └────┘ └─┘ └┘                └────────┘
typ    └─────┘                └───────┘  └────┘└─┘ └┘              └────────┘
doc    └─────┘                └───────┘   └────┘ └─┘ └┘                └────────┘ 
txt    └─────┘                └───────┘   └────┘ └─┘ └┘                └────────┘ 
par    └─────┘                └───────┘   └────┘ └─┘ └┘                └────────┘ 
pid    └───┘└┘                └───────┘   └────┘ └─┘ └┘                └────────┘ 
st   ────────────────────────────────────────────────────────────────────────────────────
903      (λy, (ext_chart_at I' c).to_fun c) := rfl,
id             └──────────┘ └┘                └─┘
src  ───┘  └─┘ └──────────┘   └───────┘ └───┘└─┘
typ  ───┘  └─┘ └──────────┘└┘ └───────┘└───┘└─┘
doc  ───┘  └─┘ └──────────┘   └───────┘ └───┘
txt  ───┘  └─┘                └───────┘ └───┘
par  ───┘  └─┘                └───────┘ └───┘
pid  ───┘  └─┘                └───────┘ └──┘
st   ────────────────────────────────────────────┘└─
904    rw [written_in_ext_chart_at, this],
id         └─────────────────────┘  └──┘
src    └──┘└─────────────────────┘└┘    
typ    └──┘└─────────────────────┘└┘└──┘
doc    └──┘└─────────────────────┘└┘    
txt    └──┘                       └┘    
par    └──┘                       └┘    
pid      └┘                       └┘    
st   ────────────────────────────┘└────┘└──
905    apply has_fderiv_within_at_const
id           └────────────────────────┘
src    └────┘└────────────────────────┘
typ    └────┘└────────────────────────┘
doc    └────┘                          
txt    └────┘                          
par    └────┘                          
pid                                   
st   ──────────────────────────────────┘
906  end
st   └─┘
907  
908  theorem has_mfderiv_within_at_const (c : M') (s : set M) (x : M) :
id                                            └┘       └─┘        
src                                                    └─┘
typ                                           └┘       └─┘        
909    has_mfderiv_within_at I I' (λy : M, c) s x
id     └───────────────────┘  └┘            
src    └───────────────────┘
typ    └───────────────────┘  └┘            
doc    └───────────────────┘
910    (continuous_linear_map.zero : tangent_space I x →L[𝕜] tangent_space I' c) :=
id      └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
src     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
doc     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
911  (has_mfderiv_at_const I I' c x).has_mfderiv_within_at
id    └──────────────────┘  └┘   └───────────────────┘
src   └──────────────────┘          └───────────────────┘
typ   └──────────────────┘  └┘   └───────────────────┘
912  
913  lemma mdifferentiable_at_const : mdifferentiable_at I I' (λy : M, c) x :=
id                                    └────────────────┘  └┘           
src                                   └────────────────┘
typ                                   └────────────────┘  └┘           
doc                                   └────────────────┘
914  (has_mfderiv_at_const I I' c x).mdifferentiable_at
id    └──────────────────┘  └┘   └────────────────┘
src   └──────────────────┘          └────────────────┘
typ   └──────────────────┘  └┘   └────────────────┘
915  
916  lemma mdifferentiable_within_at_const : mdifferentiable_within_at I I' (λy : M, c) s x :=
id                                           └───────────────────────┘  └┘            
src                                          └───────────────────────┘
typ                                          └───────────────────────┘  └┘            
doc                                          └───────────────────────┘
917  (mdifferentiable_at_const I I').mdifferentiable_within_at
id    └──────────────────────┘  └┘ └───────────────────────┘
src   └──────────────────────┘      └───────────────────────┘
typ   └──────────────────────┘  └┘ └───────────────────────┘
918  
919  lemma mdifferentiable_const : mdifferentiable I I' (λy : M, c) :=
id                                 └─────────────┘  └┘         
src                                └─────────────┘
typ                                └─────────────┘  └┘         
doc                                └─────────────┘
920  λx, mdifferentiable_at_const I I'
id      └──────────────────────┘  └┘
src      └──────────────────────┘
typ     └──────────────────────┘  └┘
921  
922  lemma mdifferentiable_on_const : mdifferentiable_on I I' (λy : M, c) s :=
id                                    └────────────────┘  └┘           
src                                   └────────────────┘
typ                                   └────────────────┘  └┘           
doc                                   └────────────────┘
923  (mdifferentiable_const I I').mdifferentiable_on
id    └───────────────────┘  └┘ └────────────────┘
src   └───────────────────┘      └────────────────┘
typ   └───────────────────┘  └┘ └────────────────┘
924  
925  @[simp] lemma mfderiv_const : mfderiv I I' (λy : M, c) x =
id                                 └─────┘  └┘            
src                                └─────┘                    
typ                                └─────┘  └┘            
doc    └──┘                        └─────┘
926    (continuous_linear_map.zero : tangent_space I x →L[𝕜] tangent_space I' c) :=
id      └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
src     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
doc     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
927  has_mfderiv_at.mfderiv (has_mfderiv_at_const I I' c x)
id   └────────────────────┘  └──────────────────┘  └┘  
src  └────────────────────┘  └──────────────────┘
typ  └────────────────────┘  └──────────────────┘  └┘  
928  
929  lemma mfderiv_within_const (hxs : unique_mdiff_within_at I s x) :
id                                     └────────────────────┘   
src                                    └────────────────────┘
typ                                    └────────────────────┘   
doc                                    └────────────────────┘
930    mfderiv_within I I' (λy : M, c) s x =
id     └────────────┘  └┘             
src    └────────────┘                      
typ    └────────────┘  └┘             
doc    └────────────┘
931    (continuous_linear_map.zero : tangent_space I x →L[𝕜] tangent_space I' c) :=
id      └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
src     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
typ     └────────────────────────┘   └───────────┘   └─┘ └───────────┘ └┘ 
doc     └────────────────────────┘   └───────────┘     └─┘  └───────────┘
932  begin
st   └─────
933    rw mdifferentiable.mfderiv_within (mdifferentiable_at_const I I') hxs,
id        └────────────────────────────┘  └──────────────────────┘  └┘  └─┘
src    └─┘└────────────────────────────┘ └──────────────────────┘   └┘
typ    └─┘└────────────────────────────┘ └──────────────────────┘└┘└┘└─┘
doc    └─┘                                                          └┘
txt    └─┘                                                          └┘
par    └─┘                                                          └┘
pid                                                                └┘
st   ──────────────────────────────────────────────────────────────────────┘└─
934    { exact mfderiv_const I I' },
id             └───────────┘  └┘
src      └────┘└───────────┘   
typ      └────┘└───────────┘└┘
doc      └────┘                
txt      └────┘                
par      └────┘                
pid                           
st   ───┘└───────────────────────┘└┘
935    { apply_instance }
src      └─────────────┘
typ      └─────────────┘
doc      └─────────────┘
txt      └─────────────┘
par      └─────────────┘
pid                    
st   ──────────────────┘└─
936  end
st   ──┘
937  
938  end const
939  
940  section model_with_corners
941  /-! #### Model with corners -/
942  
943  lemma model_with_corners_mdifferentiable_on_to_fun :
944    mdifferentiable I (model_with_corners_self 𝕜 E) I.to_fun :=
id     └─────────────┘   └─────────────────────┘    └─────┘
src    └─────────────┘    └─────────────────────┘       └─────┘
typ    └─────────────┘   └─────────────────────┘    └─────┘
doc    └─────────────┘    └─────────────────────┘
945  begin
st   └─────
946    simp only [mdifferentiable, mdifferentiable_at, written_in_ext_chart_at, ext_chart_at,
id                └─────────────┘  └────────────────┘  └─────────────────────┘  └──────────┘
src    └─────────┘└─────────────┘└┘└────────────────┘└┘└─────────────────────┘└┘└──────────┘└─
typ    └─────────┘└─────────────┘└┘└────────────────┘└┘└─────────────────────┘└┘└──────────┘└─
doc    └─────────┘└─────────────┘└┘└────────────────┘└┘└─────────────────────┘└┘└──────────┘└─
txt    └─────────┘               └┘                  └┘                       └┘            └─
par    └─────────┘               └┘                  └┘                       └┘            └─
pid        └──┘└┘               └┘                  └┘                       └┘            └─
st   ─────────────────────────────────────────────────────────────────────────────────────────
947               local_equiv.refl_trans, local_equiv.refl_to_fun, model_with_corners_self_local_equiv,
id                └────────────────────┘  └─────────────────────┘  └─────────────────────────────────┘
src  ────────────┘└────────────────────┘└┘└─────────────────────┘└┘└─────────────────────────────────┘└─
typ  ────────────┘└────────────────────┘└┘└─────────────────────┘└┘└─────────────────────────────────┘└─
doc  ────────────┘                      └┘                       └┘└─────────────────────────────────┘└─
txt  ────────────┘                      └┘                       └┘                                   └─
par  ────────────┘                      └┘                       └┘                                   └─
pid  ────────────┘                      └┘                       └┘                                   └─
st   ───────────────────────────────────────────────────────────────────────────────────────────────────
948               chart_at_model_space_eq, local_homeomorph.refl_local_equiv, function.comp.left_id],
id                └─────────────────────┘  └───────────────────────────────┘  └───────────────────┘
src  ────────────┘└─────────────────────┘└┘└───────────────────────────────┘└┘└───────────────────┘
typ  ────────────┘└─────────────────────┘└┘└───────────────────────────────┘└┘└───────────────────┘
doc  ────────────┘└─────────────────────┘└┘                                 └┘                     
txt  ────────────┘                       └┘                                 └┘                     
par  ────────────┘                       └┘                                 └┘                     
pid  ────────────┘                       └┘                                 └┘                     
st   ──────────────────────────────────────────────────────────────────────────────────────────────┘└─
949    assume x,
src    └──────┘
typ    └──────┘
doc    └──────┘
txt    └──────┘
par    └──────┘
pid    └──────┘
st   ─────────┘└─
950    refine ⟨I.continuous_to_fun.continuous_at, _⟩,
id             └───────────────────────────────┘
src    └─────┘ └───────────────────────────────┘└──┘
typ    └─────┘ └───────────────────────────────┘└──┘
doc    └─────┘                                  └──┘
txt    └─────┘                                  └──┘
par    └─────┘                                  └──┘
pid                                            └──┘
st   ──────────────────────────────────────────────┘└─
951    have : differentiable_within_at 𝕜 id (range I.to_fun) (I.to_fun x) :=
id            └──────────────────────┘  └┘  └───┘            └──────┘ 
src    └─────┘└──────────────────────┘ └┘ └───┘        └┘ └──────┘ └────
typ    └─────┘└──────────────────────┘└┘ └───┘        └┘ └──────┘└────
doc    └─────┘└──────────────────────┘    └───┘        └┘          └────
txt    └─────┘                                         └┘          └────
par    └─────┘                                         └┘          └────
pid    └───┘└┘                                         └┘          └───
st   ────────────────────────────────────────────────────────────────────────
952      differentiable_at_id.differentiable_within_at,
id       └───────────────────────────────────────────┘
src  ───┘└───────────────────────────────────────────┘
typ  ───┘└───────────────────────────────────────────┘
doc  ───┘
txt  ───┘
par  ───┘
pid  ───┘
st   ────────────────────────────────────────────────┘└─
953    apply this.congr,
src    └────┘
typ    └────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ─────────────────┘└─
954    { simp [model_with_corners_right_inv] {contextual := tt} },
id             └──────────────────────────┘                 └┘
src      └────┘└──────────────────────────┘└┘ └────────────┘└┘└┘
typ      └────┘└──────────────────────────┘└┘ └────────────┘└┘└┘
doc      └────┘                            └┘ └────────────┘  └┘
txt      └────┘                            └┘ └────────────┘  └┘
par      └────┘                            └┘ └────────────┘  └┘
pid                                       └────────────┘  
st   ───┘└─────────────────────────────────────────────────────┘└┘
955    { simp [model_with_corners_left_inv] }
id             └─────────────────────────┘
src      └────┘└─────────────────────────┘└┘
typ      └────┘└─────────────────────────┘└┘
doc      └────┘                           └┘
txt      └────┘                           └┘
par      └────┘                           └┘
pid                                     
st   ──────────────────────────────────────┘└─
956  end
st   ──┘
957  
958  lemma model_with_corners_mdifferentiable_on_inv_fun :
959    mdifferentiable_on (model_with_corners_self 𝕜 E) I I.inv_fun (range I.to_fun) :=
id     └────────────────┘  └─────────────────────┘     └──────┘  └───┘ └─────┘
src    └────────────────┘  └─────────────────────┘         └──────┘  └───┘  └─────┘
typ    └────────────────┘  └─────────────────────┘     └──────┘  └───┘ └─────┘
doc    └────────────────┘  └─────────────────────┘                   └───┘
960  begin
st   └─────
961    simp only [mdifferentiable_on, -mem_range, mdifferentiable_within_at, written_in_ext_chart_at,
id                └────────────────┘              └───────────────────────┘  └─────────────────────┘
src    └─────────┘└────────────────┘└────────────┘└───────────────────────┘└┘└─────────────────────┘└─
typ    └─────────┘└────────────────┘└────────────┘└───────────────────────┘└┘└─────────────────────┘└─
doc    └─────────┘└────────────────┘└────────────┘└───────────────────────┘└┘└─────────────────────┘└─
txt    └─────────┘                  └────────────┘                         └┘                       └─
par    └─────────┘                  └────────────┘                         └┘                       └─
pid        └──┘└┘                  └────────────┘                         └┘                       └─
st   ─────────────────────────────────────────────────────────────────────────────────────────────────
962               ext_chart_at, local_equiv.refl_trans, local_equiv.refl_to_fun, preimage_id, id.def,
id                └──────────┘  └────────────────────┘  └─────────────────────┘  └─────────┘  └────┘
src  ────────────┘└──────────┘└┘└────────────────────┘└┘└─────────────────────┘└┘└─────────┘└┘└────┘└─
typ  ────────────┘└──────────┘└┘└────────────────────┘└┘└─────────────────────┘└┘└─────────┘└┘└────┘└─
doc  ────────────┘└──────────┘└┘                      └┘                       └┘           └┘      └─
txt  ────────────┘            └┘                      └┘                       └┘           └┘      └─
par  ────────────┘            └┘                      └┘                       └┘           └┘      └─
pid  ────────────┘            └┘                      └┘                       └┘           └┘      └─
st   ─────────────────────────────────────────────────────────────────────────────────────────────────
963               inter_univ, model_with_corners_self_local_equiv, local_equiv.refl_inv_fun, range_id,
id                └────────┘  └─────────────────────────────────┘  └──────────────────────┘  └──────┘
src  ────────────┘└────────┘└┘└─────────────────────────────────┘└┘└──────────────────────┘└┘└──────┘└─
typ  ────────────┘└────────┘└┘└─────────────────────────────────┘└┘└──────────────────────┘└┘└──────┘└─
doc  ────────────┘          └┘└─────────────────────────────────┘└┘                        └┘        └─
txt  ────────────┘          └┘                                   └┘                        └┘        └─
par  ────────────┘          └┘                                   └┘                        └┘        └─
pid  ────────────┘          └┘                                   └┘                        └┘        └─
st   ──────────────────────────────────────────────────────────────────────────────────────────────────
964               function.comp.right_id, chart_at_model_space_eq, local_homeomorph.refl_local_equiv],
id                └────────────────────┘  └─────────────────────┘  └───────────────────────────────┘
src  ────────────┘└────────────────────┘└┘└─────────────────────┘└┘└───────────────────────────────┘
typ  ────────────┘└────────────────────┘└┘└─────────────────────┘└┘└───────────────────────────────┘
doc  ────────────┘                      └┘└─────────────────────┘└┘                                 
txt  ────────────┘                      └┘                       └┘                                 
par  ────────────┘                      └┘                       └┘                                 
pid  ────────────┘                      └┘                       └┘                                 
st   ───────────────────────────────────────────────────────────────────────────────────────────────┘└─
965    assume x hx,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid    └─────────┘
st   ────────────┘└─
966    refine ⟨I.continuous_inv_fun.continuous_at.continuous_within_at, _⟩,
id             └─────────────────────────────────────────────────────┘
src    └─────┘ └─────────────────────────────────────────────────────┘└──┘
typ    └─────┘ └─────────────────────────────────────────────────────┘└──┘
doc    └─────┘                                                        └──┘
txt    └─────┘                                                        └──┘
par    └─────┘                                                        └──┘
pid                                                                  └──┘
st   ────────────────────────────────────────────────────────────────────┘└─
967    have : differentiable_within_at 𝕜 id (range I.to_fun) x :=
id            └──────────────────────┘  └┘  └───┘ └──────┘  
src    └─────┘└──────────────────────┘ └┘ └───┘└──────┘└┘ └───
typ    └─────┘└──────────────────────┘└┘ └───┘└──────┘└┘└───
doc    └─────┘└──────────────────────┘    └───┘        └┘ └───
txt    └─────┘                                         └┘ └───
par    └─────┘                                         └┘ └───
pid    └───┘└┘                                         └┘ └───
st   ─────────────────────────────────────────────────────────────
968      differentiable_at_id.differentiable_within_at,
id       └───────────────────────────────────────────┘
src  ───┘└───────────────────────────────────────────┘
typ  ───┘└───────────────────────────────────────────┘
doc  ───┘
txt  ───┘
par  ───┘
pid  ───┘
st   ────────────────────────────────────────────────┘└─
969    apply this.congr,
src    └────┘
typ    └────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ─────────────────┘└─
970    { simp [model_with_corners_right_inv] {contextual := tt} },
id             └──────────────────────────┘                 └┘
src      └────┘└──────────────────────────┘└┘ └────────────┘└┘└┘
typ      └────┘└──────────────────────────┘└┘ └────────────┘└┘└┘
doc      └────┘                            └┘ └────────────┘  └┘
txt      └────┘                            └┘ └────────────┘  └┘
par      └────┘                            └┘ └────────────┘  └┘
pid                                       └────────────┘  
st   ───┘└─────────────────────────────────────────────────────┘└┘
971    { simp [model_with_corners_right_inv, hx] }
id             └──────────────────────────┘  └┘
src      └────┘└──────────────────────────┘└┘  └┘
typ      └────┘└──────────────────────────┘└┘└┘└┘
doc      └────┘                            └┘  └┘
txt      └────┘                            └┘  └┘
par      └────┘                            └┘  └┘
pid                                      └┘  
st   ───────────────────────────────────────────┘└─
972  end
st   ──┘
973  
974  end model_with_corners
975  
976  section charts
977  
978  variable {e : local_homeomorph M H}
id                 └──────────────┘
src                └──────────────┘
typ                └──────────────┘
doc                └──────────────┘
979  
980  lemma mdifferentiable_at_atlas_to_fun (h : e ∈ atlas H M) {x : M} (hx : x ∈ e.source) :
id                                                └───┘                   └─────┘
src                                                └───┘                        └─────┘
typ                                               └───┘                   └─────┘
981    mdifferentiable_at I I e.to_fun x :=
id     └────────────────┘   └─────┘ 
src    └────────────────┘      └─────┘
typ    └────────────────┘   └─────┘ 
doc    └────────────────┘
982  begin
st   └─────
983    refine ⟨(e.continuous_to_fun x hx).continuous_at (mem_nhds_sets e.open_source hx), _⟩,
id              └─────────────────┘                     └───────────┘ └───────────┘ └┘
src    └─────┘  └─────────────────┘   └──────────────┘ └───────────┘└───────────┘  └───┘
typ    └─────┘  └─────────────────┘  └──────────────┘ └───────────┘└───────────┘└┘└───┘
doc    └─────┘                        └──────────────┘                             └───┘
txt    └─────┘                        └──────────────┘                             └───┘
par    └─────┘                        └──────────────┘                             └───┘
pid                                  └──────────────┘                             └───┘
st   ──────────────────────────────────────────────────────────────────────────────────────┘└─
984    have zero_one : ((0 : ℕ) : with_top ℕ) < ⊤, by simp,
id                                └──────┘     
src    └──────────────┘  └──┘ └──┘└──────┘ └┘     └──┘
typ    └──────────────┘  └──┘ └──┘└──────┘ └┘     └──┘
doc    └──────────────┘  └──┘ └──┘         └┘       └──┘
txt    └──────────────┘  └──┘ └──┘         └┘       └──┘
par    └──────────────┘  └──┘ └──┘         └┘       └──┘
pid    └───────────┘└─┘  └──┘ └──┘         └┘ 
st   ───────────────────────────────────────────┘         └─
985    have mem : I.to_fun ((chart_at H x).to_fun x) ∈
id                                                   
src    └─────────┘                    └───────┘ └┘
typ    └─────────┘                    └───────┘ └┘
doc    └─────────┘                    └───────┘ └┘ 
txt    └─────────┘                    └───────┘ └┘ 
par    └─────────┘                    └───────┘ └┘ 
pid    └──────┘└─┘                    └───────┘ └┘ 
st   ──────────────────────────────────────────────────
986      I.inv_fun ⁻¹' ((chart_at H x).symm ≫ₕ e).source ∩ range I.to_fun,
id       └───────┘ └─┘   └──────┘         └┘           └───┘ └──────┘
src  ───┘└───────┘└─┘  └──────┘  └─────┘└┘ └───────┘└───┘└──────┘
typ  ───┘└───────┘└─┘  └──────┘└─────┘└┘└───────┘└───┘└──────┘
doc  ───┘         └─┘            └─────┘└┘ └───────┘ └───┘
txt  ───┘                        └─────┘   └───────┘      
par  ───┘                        └─────┘   └───────┘      
pid  ───┘                        └─────┘   └───────┘      
st   ───────────────────────────────────────────────────────────────────┘└─
987    { simp only [mem_preimage, mem_inter_eq, model_with_corners_left_inv, mem_range_self,
id                  └──────────┘  └──────────┘  └─────────────────────────┘  └────────────┘
src      └─────────┘└──────────┘└┘└──────────┘└┘└─────────────────────────┘└┘└────────────┘└─
typ      └─────────┘└──────────┘└┘└──────────┘└┘└─────────────────────────┘└┘└────────────┘└─
doc      └─────────┘            └┘            └┘                           └┘              └─
txt      └─────────┘            └┘            └┘                           └┘              └─
par      └─────────┘            └┘            └┘                           └┘              └─
pid          └──┘└┘            └┘            └┘                           └┘              └─
st   ───┘└───────────────────────────────────────────────────────────────────────────────────
988        local_homeomorph.trans_source, local_homeomorph.symm_source, local_homeomorph.symm_to_fun,
id         └───────────────────────────┘  └──────────────────────────┘  └──────────────────────────┘
src  ─────┘└───────────────────────────┘└┘└──────────────────────────┘└┘└──────────────────────────┘└─
typ  ─────┘└───────────────────────────┘└┘└──────────────────────────┘└┘└──────────────────────────┘└─
doc  ─────┘                             └┘                            └┘                            └─
txt  ─────┘                             └┘                            └┘                            └─
par  ─────┘                             └┘                            └┘                            └─
pid  ─────┘                             └┘                            └┘                            └─
st   ─────────────────────────────────────────────────────────────────────────────────────────────────
989        and_true],
id         └──────┘
src  ─────┘└──────┘
typ  ─────┘└──────┘
doc  ─────┘        
txt  ─────┘        
par  ─────┘        
pid  ─────┘        
st   ──────────────┘└─
990      split,
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
st   ────────┘└─
991      { exact local_equiv.map_source _ (mem_chart_source _ _) },
id               └────────────────────┘    └──────────────┘
src        └────┘└────────────────────┘└─┘ └──────────────┘└────┘
typ        └────┘└────────────────────┘└─┘ └──────────────┘└────┘
doc        └────┘                      └─┘                 └────┘
txt        └────┘                      └─┘                 └────┘
par        └────┘                      └─┘                 └────┘
pid                                   └─┘                 └───┘
st   ─────┘└────────────────────────────────────────────────────┘└┘
992      { rw local_equiv.left_inv _ (mem_chart_source _ _), exact hx } },
id            └──────────────────┘    └──────────────┘             └┘
src        └─┘└──────────────────┘└─┘ └──────────────┘└───┘  └────┘  
typ        └─┘└──────────────────┘└─┘ └──────────────┘└───┘  └────┘└┘
doc        └─┘                    └─┘                 └───┘  └────┘  
txt        └─┘                    └─┘                 └───┘  └────┘  
par        └─┘                    └─┘                 └───┘  └────┘  
pid                              └─┘                 └───┘         
st   ─────────────────────────────────────────────────────┘└─────────┘└──┘
993    have : (chart_at H x).symm.trans e ∈ times_cont_diff_groupoid ⊤ I :=
id             └──────┘                  └──────────────────────┘   
src    └─────┘ └──────┘  └───────────┘  └──────────────────────┘  └───
typ    └─────┘ └──────┘└───────────┘ └──────────────────────┘ └───
doc    └─────┘           └───────────┘  └──────────────────────┘  └───
txt    └─────┘           └───────────┘                            └───
par    └─────┘           └───────────┘                            └───
pid    └───┘└┘           └───────────┘                            └───
st   ───────────────────────────────────────────────────────────────────────
994      has_groupoid.compatible _ (chart_mem_atlas H x) h,
id       └─────────────────────┘    └─────────────┘    
src  ───┘└─────────────────────┘└─┘ └─────────────┘  └┘
typ  ───┘└─────────────────────┘└─┘ └─────────────┘└┘
doc  ───┘                       └─┘                  └┘
txt  ───┘                       └─┘                  └┘
par  ───┘                       └─┘                  └┘
pid  ───┘                       └─┘                  └┘
st   ────────────────────────────────────────────────────┘└─
995    have A : times_cont_diff_on 𝕜 ⊤
id              └────────────────┘ 
src    └───────┘└────────────────┘  
typ    └───────┘└────────────────┘ 
doc    └───────┘└────────────────┘  
txt    └───────┘                    
par    └───────┘                    
pid    └────┘└─┘                    
st   ──────────────────────────────────
996      (I.to_fun ∘ ((chart_at H x).symm.trans e).to_fun ∘ I.inv_fun)
id                 
src  ───┘                     └───────────┘ └───────┘          └─
typ  ───┘                     └───────────┘ └───────┘          └─
doc  ───┘                      └───────────┘ └───────┘          └─
txt  ───┘                      └───────────┘ └───────┘          └─
par  ───┘                      └───────────┘ └───────┘          └─
pid  ───┘                      └───────────┘ └───────┘          └─
st   ──────────────────────────────────────────────────────────────────
997      (I.inv_fun ⁻¹' ((chart_at H x).symm.trans e).source ∩ range I.to_fun) :=
id        └───────┘       └──────┘                          └───┘ └──────┘
src  ───┘ └───────┘     └──────┘  └───────────┘ └───────┘ └───┘└──────┘└────
typ  ───┘ └───────┘     └──────┘└───────────┘└───────┘ └───┘└──────┘└────
doc  ───┘                         └───────────┘ └───────┘ └───┘        └────
txt  ───┘                         └───────────┘ └───────┘              └────
par  ───┘                         └───────────┘ └───────┘              └────
pid  ───┘                         └───────────┘ └───────┘              └───
st   ─────────────────────────────────────────────────────────────────────────────
998      this.1,
id       └──┘
src  ───┘    └┘
typ  ───┘└──┘└┘
doc  ───┘    └┘
txt  ───┘    └┘
par  ───┘    └┘
pid  ───┘    └┘
st   ─────────┘└─
999    have B := A.2 _ zero_one (I.to_fun ((chart_at H x).to_fun x)) mem,
id                    └──────┘  └──────┘   └──────┘               └─┘
src    └────────┘ └───┘         └──────┘  └──────┘  └───────┘ └─┘
typ    └────────┘└───┘└──────┘ └──────┘  └──────┘ └───────┘└─┘└─┘
doc    └────────┘ └───┘                             └───────┘ └─┘
txt    └────────┘ └───┘                             └───────┘ └─┘
par    └────────┘ └───┘                             └───────┘ └─┘
pid    └────┘└─┘ └───┘                             └───────┘ └─┘
st   ──────────────────────────────────────────────────────────────────┘└─
1000    simp only [local_homeomorph.trans_to_fun, iterated_fderiv_within_zero, local_homeomorph.symm_to_fun] at B,
id                └───────────────────────────┘  └─────────────────────────┘  └──────────────────────────┘
src    └─────────┘└───────────────────────────┘└┘└─────────────────────────┘└┘└──────────────────────────┘└────┘
typ    └─────────┘└───────────────────────────┘└┘└─────────────────────────┘└┘└──────────────────────────┘└────┘
doc    └─────────┘                             └┘                           └┘                            └────┘
txt    └─────────┘                             └┘                           └┘                            └────┘
par    └─────────┘                             └┘                           └┘                            └────┘
pid        └──┘└┘                             └┘                           └┘                            └──┘
st   ──────────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1001    rw [inter_comm, differentiable_within_at_inter
id         └────────┘  └────────────────────────────┘
src    └──┘└────────┘└┘└────────────────────────────┘
typ    └──┘└────────┘└┘└────────────────────────────┘
doc    └──┘          └┘                              
txt    └──┘          └┘                              
par    └──┘          └┘                              
pid      └┘          └┘                              
st   ───────────────┘└────────────────────────────────
1002      (mem_nhds_sets (I.continuous_inv_fun _ (local_homeomorph.open_source _)) mem.1)] at B,
id        └───────────┘  └──────────────────┘    └──────────────────────────┘     └─┘
src  ───┘ └───────────┘ └──────────────────┘└─┘ └──────────────────────────┘└───┘   └───────┘
typ  ───┘ └───────────┘ └──────────────────┘└─┘ └──────────────────────────┘└───┘└─┘└───────┘
doc  ───┘                                   └─┘                             └───┘   └───────┘
txt  ───┘                                   └─┘                             └───┘   └───────┘
par  ───┘                                   └─┘                             └───┘   └───────┘
pid  ───┘                                   └─┘                             └───┘   └──┘└───┘
st   ──────────────────────────────────────────────────────────────────────────────────┘└───┘└─
1003    simpa [written_in_ext_chart_at, ext_chart_at]
id            └─────────────────────┘  └──────────┘
src    └─────┘└─────────────────────┘└┘└──────────┘└┘
typ    └─────┘└─────────────────────┘└┘└──────────┘└┘
doc    └─────┘└─────────────────────┘└┘└──────────┘└┘
txt    └─────┘                       └┘            └┘
par    └─────┘                       └┘            └┘
pid                                └┘            
st   ───────────────────────────────────────────────┘
1004  end
st   └─┘
1005  
1006  lemma mdifferentiable_on_atlas_to_fun (h : e ∈ atlas H M) :
id                                                └───┘  
src                                                └───┘
typ                                               └───┘  
1007    mdifferentiable_on I I e.to_fun e.source :=
id     └────────────────┘   └─────┘ └─────┘
src    └────────────────┘      └─────┘  └─────┘
typ    └────────────────┘   └─────┘ └─────┘
doc    └────────────────┘
1008  λx hx, (mdifferentiable_at_atlas_to_fun I h hx).mdifferentiable_within_at
id     └┘   └─────────────────────────────┘   └┘ └───────────────────────┘
src          └─────────────────────────────┘        └───────────────────────┘
typ    └┘   └─────────────────────────────┘   └┘ └───────────────────────┘
1009  
1010  lemma mdifferentiable_at_atlas_inv_fun (h : e ∈ atlas H M) {x : H} (hx : x ∈ e.target) :
id                                                 └───┘                   └─────┘
src                                                 └───┘                        └─────┘
typ                                                └───┘                   └─────┘
1011    mdifferentiable_at I I e.inv_fun x :=
id     └────────────────┘   └──────┘ 
src    └────────────────┘      └──────┘
typ    └────────────────┘   └──────┘ 
doc    └────────────────┘
1012  begin
st   └─────
1013    refine ⟨(e.continuous_inv_fun x hx).continuous_at (mem_nhds_sets e.open_target hx), _⟩,
id              └──────────────────┘                     └───────────┘ └───────────┘ └┘
src    └─────┘  └──────────────────┘   └──────────────┘ └───────────┘└───────────┘  └───┘
typ    └─────┘  └──────────────────┘  └──────────────┘ └───────────┘└───────────┘└┘└───┘
doc    └─────┘                         └──────────────┘                             └───┘
txt    └─────┘                         └──────────────┘                             └───┘
par    └─────┘                         └──────────────┘                             └───┘
pid                                   └──────────────┘                             └───┘
st   ───────────────────────────────────────────────────────────────────────────────────────┘└─
1014    have zero_one : ((0 : ℕ) : with_top ℕ) < ⊤, by simp,
id                                └──────┘     
src    └──────────────┘  └──┘ └──┘└──────┘ └┘     └──┘
typ    └──────────────┘  └──┘ └──┘└──────┘ └┘     └──┘
doc    └──────────────┘  └──┘ └──┘         └┘       └──┘
txt    └──────────────┘  └──┘ └──┘         └┘       └──┘
par    └──────────────┘  └──┘ └──┘         └┘       └──┘
pid    └───────────┘└─┘  └──┘ └──┘         └┘ 
st   ───────────────────────────────────────────┘         └─
1015    have mem : I.to_fun x ∈ I.inv_fun ⁻¹' (e.symm ≫ₕ chart_at H (e.inv_fun x)).source ∩ range (I.to_fun),
id                            └───────┘ └─┘  └────┘ └┘ └──────┘   └───────┘            └───┘  └──────┘
src    └─────────┘         └───────┘└─┘ └────┘└┘└──────┘  └───────┘ └────────┘└───┘ └──────┘
typ    └─────────┘         └───────┘└─┘ └────┘└┘└──────┘ └───────┘└────────┘└───┘ └──────┘
doc    └─────────┘                   └─┘ └────┘└┘                    └────────┘ └───┘         
txt    └─────────┘                                                   └────────┘               
par    └─────────┘                                                   └────────┘               
pid    └──────┘└─┘                                                   └────────┘               
st   ─────────────────────────────────────────────────────────────────────────────────────────────────────┘
1016      by simp only [local_homeomorph.trans_source, local_homeomorph.symm_source, mem_preimage,
id                     └───────────────────────────┘  └──────────────────────────┘  └──────────┘
src         └─────────┘└───────────────────────────┘└┘└──────────────────────────┘└┘└──────────┘└─
typ         └─────────┘└───────────────────────────┘└┘└──────────────────────────┘└┘└──────────┘└─
doc         └─────────┘                             └┘                            └┘            └─
txt         └─────────┘                             └┘                            └┘            └─
par         └─────────┘                             └┘                            └┘            └─
pid             └──┘└┘                             └┘                            └┘            └─
1017        mem_inter_eq, model_with_corners_left_inv, preimage_inter, and_true, hx, true_and,
id         └──────────┘  └─────────────────────────┘  └────────────┘  └──────┘  └┘  └──────┘
src  ─────┘└──────────┘└┘└─────────────────────────┘└┘└────────────┘└┘└──────┘└┘  └┘└──────┘└─
typ  ─────┘└──────────┘└┘└─────────────────────────┘└┘└────────────┘└┘└──────┘└┘└┘└┘└──────┘└─
doc  ─────┘            └┘                           └┘              └┘        └┘  └┘        └─
txt  ─────┘            └┘                           └┘              └┘        └┘  └┘        └─
par  ─────┘            └┘                           └┘              └┘        └┘  └┘        └─
pid  ─────┘            └┘                           └┘              └┘        └┘  └┘        └─
1018        local_homeomorph.symm_to_fun, mem_range_self, mem_chart_source],
id         └──────────────────────────┘  └────────────┘  └──────────────┘
src  ─────┘└──────────────────────────┘└┘└────────────┘└┘└──────────────┘
typ  ─────┘└──────────────────────────┘└┘└────────────┘└┘└──────────────┘
doc  ─────┘                            └┘              └┘                
txt  ─────┘                            └┘              └┘                
par  ─────┘                            └┘              └┘                
pid  ─────┘                            └┘              └┘                
st                                                                        └─
1019    have : e.symm.trans (chart_at H (e.inv_fun x)) ∈ times_cont_diff_groupoid ⊤ I :=
id            └──────────┘  └──────┘   └───────┘      └──────────────────────┘   
src    └─────┘└──────────┘ └──────┘  └───────┘ └─┘ └──────────────────────┘  └───
typ    └─────┘└──────────┘ └──────┘ └───────┘└─┘ └──────────────────────┘ └───
doc    └─────┘└──────────┘                     └─┘ └──────────────────────┘  └───
txt    └─────┘                                 └─┘                           └───
par    └─────┘                                 └─┘                           └───
pid    └───┘└┘                                 └─┘                           └───
st   ───────────────────────────────────────────────────────────────────────────────────
1020      has_groupoid.compatible _ h (chart_mem_atlas H _),
id       └─────────────────────┘     └─────────────┘ 
src  ───┘└─────────────────────┘└─┘  └─────────────┘ └─┘
typ  ───┘└─────────────────────┘└─┘ └─────────────┘└─┘
doc  ───┘                       └─┘                  └─┘
txt  ───┘                       └─┘                  └─┘
par  ───┘                       └─┘                  └─┘
pid  ───┘                       └─┘                  └─┘
st   ────────────────────────────────────────────────────┘└─
1021    have A : times_cont_diff_on 𝕜 ⊤
id              └────────────────┘ 
src    └───────┘└────────────────┘  
typ    └───────┘└────────────────┘ 
doc    └───────┘└────────────────┘  
txt    └───────┘                    
par    └───────┘                    
pid    └────┘└─┘                    
st   ──────────────────────────────────
1022      (I.to_fun ∘ (e.symm.trans (chart_at H (e.inv_fun x))).to_fun ∘ I.inv_fun)
id                 
src  ───┘                                           └─────────┘          └─
typ  ───┘                                           └─────────┘          └─
doc  ───┘                                            └─────────┘          └─
txt  ───┘                                            └─────────┘          └─
par  ───┘                                            └─────────┘          └─
pid  ───┘                                            └─────────┘          └─
st   ──────────────────────────────────────────────────────────────────────────────
1023      (I.inv_fun ⁻¹' (e.symm.trans (chart_at H (e.inv_fun x))).source ∩ range I.to_fun) :=
id        └───────┘      └──────────┘  └──────┘   └───────┘              └───┘ └──────┘
src  ───┘ └───────┘    └──────────┘ └──────┘  └───────┘ └─────────┘ └───┘└──────┘└────
typ  ───┘ └───────┘    └──────────┘ └──────┘ └───────┘└─────────┘ └───┘└──────┘└────
doc  ───┘              └──────────┘                     └─────────┘ └───┘        └────
txt  ───┘                                               └─────────┘              └────
par  ───┘                                               └─────────┘              └────
pid  ───┘                                               └─────────┘              └───
st   ─────────────────────────────────────────────────────────────────────────────────────────
1024      this.1,
id       └──┘
src  ───┘    └┘
typ  ───┘└──┘└┘
doc  ───┘    └┘
txt  ───┘    └┘
par  ───┘    └┘
pid  ───┘    └┘
st   ─────────┘└─
1025    have B := A.2 _ zero_one (I.to_fun x) mem,
id                    └──────┘  └──────┘   └─┘
src    └────────┘ └───┘         └──────┘ └┘
typ    └────────┘└───┘└──────┘ └──────┘└┘└─┘
doc    └────────┘ └───┘                  └┘
txt    └────────┘ └───┘                  └┘
par    └────────┘ └───┘                  └┘
pid    └────┘└─┘ └───┘                  └┘
st   ──────────────────────────────────────────┘└─
1026    simp only [local_homeomorph.trans_to_fun, iterated_fderiv_within_zero, local_homeomorph.symm_to_fun] at B,
id                └───────────────────────────┘  └─────────────────────────┘  └──────────────────────────┘
src    └─────────┘└───────────────────────────┘└┘└─────────────────────────┘└┘└──────────────────────────┘└────┘
typ    └─────────┘└───────────────────────────┘└┘└─────────────────────────┘└┘└──────────────────────────┘└────┘
doc    └─────────┘                             └┘                           └┘                            └────┘
txt    └─────────┘                             └┘                           └┘                            └────┘
par    └─────────┘                             └┘                           └┘                            └────┘
pid        └──┘└┘                             └┘                           └┘                            └──┘
st   ──────────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1027    rw [inter_comm, differentiable_within_at_inter
id         └────────┘  └────────────────────────────┘
src    └──┘└────────┘└┘└────────────────────────────┘
typ    └──┘└────────┘└┘└────────────────────────────┘
doc    └──┘          └┘                              
txt    └──┘          └┘                              
par    └──┘          └┘                              
pid      └┘          └┘                              
st   ───────────────┘└────────────────────────────────
1028      (mem_nhds_sets (I.continuous_inv_fun _ (local_homeomorph.open_source _)) mem.1)] at B,
id        └───────────┘  └──────────────────┘    └──────────────────────────┘     └─┘
src  ───┘ └───────────┘ └──────────────────┘└─┘ └──────────────────────────┘└───┘   └───────┘
typ  ───┘ └───────────┘ └──────────────────┘└─┘ └──────────────────────────┘└───┘└─┘└───────┘
doc  ───┘                                   └─┘                             └───┘   └───────┘
txt  ───┘                                   └─┘                             └───┘   └───────┘
par  ───┘                                   └─┘                             └───┘   └───────┘
pid  ───┘                                   └─┘                             └───┘   └──┘└───┘
st   ──────────────────────────────────────────────────────────────────────────────────┘└───┘└─
1029    simpa [written_in_ext_chart_at, ext_chart_at],
id            └─────────────────────┘  └──────────┘
src    └─────┘└─────────────────────┘└┘└──────────┘
typ    └─────┘└─────────────────────┘└┘└──────────┘
doc    └─────┘└─────────────────────┘└┘└──────────┘
txt    └─────┘                       └┘            
par    └─────┘                       └┘            
pid                                └┘            
st   ──────────────────────────────────────────────┘└─
1030  end
st   ──┘
1031  
1032  lemma mdifferentiable_on_atlas_inv_fun (h : e ∈ atlas H M) :
id                                                 └───┘  
src                                                 └───┘
typ                                                └───┘  
1033    mdifferentiable_on I I e.inv_fun e.target :=
id     └────────────────┘   └──────┘ └─────┘
src    └────────────────┘      └──────┘  └─────┘
typ    └────────────────┘   └──────┘ └─────┘
doc    └────────────────┘
1034  λx hx, (mdifferentiable_at_atlas_inv_fun I h hx).mdifferentiable_within_at
id     └┘   └──────────────────────────────┘   └┘ └───────────────────────┘
src          └──────────────────────────────┘        └───────────────────────┘
typ    └┘   └──────────────────────────────┘   └┘ └───────────────────────┘
1035  
1036  lemma mdifferentiable_of_mem_atlas (h : e ∈ atlas H M) : e.mdifferentiable I I :=
id                                             └───┘      └──────────────┘  
src                                             └───┘         └──────────────┘
typ                                            └───┘      └──────────────┘  
doc                                                            └──────────────┘
1037  ⟨mdifferentiable_on_atlas_to_fun I h, mdifferentiable_on_atlas_inv_fun I h⟩
id    └─────────────────────────────┘    └──────────────────────────────┘  
src   └─────────────────────────────┘      └──────────────────────────────┘
typ   └─────────────────────────────┘    └──────────────────────────────┘  
1038  
1039  lemma mdifferentiable_chart (x : M) : (chart_at H x).mdifferentiable I I :=
id                                         └──────┘   └─────────────┘   
src                                         └──────┘     └─────────────┘
typ                                        └──────┘   └─────────────┘   
doc                                                      └─────────────┘
1040  mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)
id   └──────────────────────────┘    └─────────────┘
src  └──────────────────────────┘    └─────────────┘
typ  └──────────────────────────┘    └─────────────┘
1041  
1042  /-- The derivative of the chart at a base point is the chart of the tangent bundle. -/
1043  lemma bundle_mfderiv_chart_to_fun {p q : tangent_bundle I M} (h : q.1 ∈ (chart_at H p.1).source) :
id                                            └────────────┘             └──────┘    └────┘
src                                           └────────────┘                └──────┘      └────┘
typ                                           └────────────┘             └──────┘    └────┘
doc                                           └────────────┘
1044    bundle_mfderiv I I (chart_at H p.1).to_fun q = (chart_at (H × E) p).to_fun q :=
id     └────────────┘    └──────┘    └────┘     └──────┘       └────┘  
src    └────────────┘      └──────┘      └────┘      └──────┘          └────┘
typ    └────────────┘    └──────┘    └────┘     └──────┘       └────┘  
doc    └────────────┘
1045  begin
st   └─────
1046    dsimp [bundle_mfderiv],
id            └────────────┘
src    └─────┘└────────────┘
typ    └─────┘└────────────┘
doc    └─────┘└────────────┘
txt    └─────┘              
par    └─────┘              
pid                       
st   ───────────────────────┘└─
1047    rw mdifferentiable_at.mfderiv,
id        └────────────────────────┘
src    └─┘└────────────────────────┘
typ    └─┘└────────────────────────┘
doc    └─┘
txt    └─┘
par    └─┘
pid      
st   ──────────────────────────────┘└─
1048    { refl },
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
pid          
st   ───┘└───┘└┘
1049    { exact mdifferentiable_at_atlas_to_fun _ (chart_mem_atlas _ _) h }
id             └─────────────────────────────┘    └─────────────┘      
src      └────┘└─────────────────────────────┘└─┘ └─────────────┘└────┘ 
typ      └────┘└─────────────────────────────┘└─┘ └─────────────┘└────┘
doc      └────┘                               └─┘                └────┘ 
txt      └────┘                               └─┘                └────┘ 
par      └────┘                               └─┘                └────┘ 
pid                                          └─┘                └────┘ 
st   ───────────────────────────────────────────────────────────────────┘└─
1050  end
st   ──┘
1051  
1052  /-- The derivative of the inverse of the chart at a base point is the inverse of the chart of the
1053  tangent bundle. -/
1054  lemma bundle_mfderiv_chart_inv_fun {p : tangent_bundle I M} {q : H × E}
id                                           └────────────┘           
src                                          └────────────┘             
typ                                          └────────────┘           
doc                                          └────────────┘
1055    (h : q.1 ∈ (chart_at H p.1).target) :
id              └──────┘    └────┘
src              └──────┘      └────┘
typ             └──────┘    └────┘
1056    bundle_mfderiv I I (chart_at H p.1).inv_fun q = (chart_at (H × E) p).inv_fun q :=
id     └────────────┘    └──────┘    └─────┘     └──────┘       └─────┘  
src    └────────────┘      └──────┘      └─────┘      └──────┘          └─────┘
typ    └────────────┘    └──────┘    └─────┘     └──────┘       └─────┘  
doc    └────────────┘
1057  begin
st   └─────
1058    dsimp only [bundle_mfderiv],
id                 └────────────┘
src    └──────────┘└────────────┘
typ    └──────────┘└────────────┘
doc    └──────────┘└────────────┘
txt    └──────────┘              
par    └──────────┘              
pid         └───┘└┘              
st   ────────────────────────────┘└─
1059    rw mdifferentiable_at.mfderiv (mdifferentiable_at_atlas_inv_fun _ (chart_mem_atlas _ _) h),
id        └────────────────────────┘  └──────────────────────────────┘    └─────────────┘      
src    └─┘└────────────────────────┘ └──────────────────────────────┘└─┘ └─────────────┘└────┘ 
typ    └─┘└────────────────────────┘ └──────────────────────────────┘└─┘ └─────────────┘└────┘
doc    └─┘                                                           └─┘                └────┘ 
txt    └─┘                                                           └─┘                └────┘ 
par    └─┘                                                           └─┘                └────┘ 
pid                                                                 └─┘                └────┘ 
st   ───────────────────────────────────────────────────────────────────────────────────────────┘└─
1060    -- a trivial instance is needed after the rewrite, handle it right now.
st   ──────────────────────────────────────────────────────────────────────────
1061    rotate, { apply_instance },
src    └────┘    └─────────────┘
typ    └────┘    └─────────────┘
doc    └────┘    └─────────────┘
txt    └────┘    └─────────────┘
par    └────┘    └─────────────┘
pid                            
st   ───────┘└──┘└─────────────┘└┘
1062    dsimp [written_in_ext_chart_at, ext_chart_at, chart_at, manifold.chart_at,
id            └─────────────────────┘  └──────────┘
src    └─────┘└─────────────────────┘└┘└──────────┘└┘        └┘                 └─
typ    └─────┘└─────────────────────┘└┘└──────────┘└┘        └┘                 └─
doc    └─────┘└─────────────────────┘└┘└──────────┘└┘        └┘                 └─
txt    └─────┘                       └┘            └┘        └┘                 └─
par    └─────┘                       └┘            └┘        └┘                 └─
pid                                └┘            └┘        └┘                 └─
st   ─────────────────────────────────────────────────────────────────────────────
1063      basic_smooth_bundle_core.chart, basic_smooth_bundle_core.to_topological_fiber_bundle_core,
id       └────────────────────────────┘  └───────────────────────────────────────────────────────┘
src  ───┘└────────────────────────────┘└┘└───────────────────────────────────────────────────────┘└─
typ  ───┘└────────────────────────────┘└┘└───────────────────────────────────────────────────────┘└─
doc  ───┘└────────────────────────────┘└┘└───────────────────────────────────────────────────────┘└─
txt  ───┘                              └┘                                                         └─
par  ───┘                              └┘                                                         └─
pid  ───┘                              └┘                                                         └─
st   ───────────────────────────────────────────────────────────────────────────────────────────────
1064      topological_fiber_bundle_core.local_triv, topological_fiber_bundle_core.local_triv',
id       └──────────────────────────────────────┘  └───────────────────────────────────────┘
src  ───┘└──────────────────────────────────────┘└┘└───────────────────────────────────────┘└─
typ  ───┘└──────────────────────────────────────┘└┘└───────────────────────────────────────┘└─
doc  ───┘└──────────────────────────────────────┘└┘└───────────────────────────────────────┘└─
txt  ───┘                                        └┘                                         └─
par  ───┘                                        └┘                                         └─
pid  ───┘                                        └┘                                         └─
st   ─────────────────────────────────────────────────────────────────────────────────────────
1065      tangent_bundle_core],
id       └─────────────────┘
src  ───┘└─────────────────┘
typ  ───┘└─────────────────┘
doc  ───┘└─────────────────┘
txt  ───┘                   
par  ───┘                   
pid  ───┘                   
st   ───────────────────────┘└─
1066    rw local_equiv.right_inv,
id        └───────────────────┘
src    └─┘└───────────────────┘
typ    └─┘└───────────────────┘
doc    └─┘
txt    └─┘
par    └─┘
pid      
st   ─────────────────────────┘└─
1067    exact h
id           
src    └────┘ 
typ    └────┘
doc    └────┘ 
txt    └────┘ 
par    └────┘ 
pid          
st   ─────────┘
1068  end
st   └─┘
1069  
1070  end charts
1071  
1072  end specific_functions
1073  
1074  section mfderiv_fderiv
1075  
1076  /-! ### Relations between vector space derivative and manifold derivative
1077  
1078  The manifold derivative `mfderiv`, when considered on the model vector space with its trivial
1079  manifold structure, coincides with the usual Frechet derivative `fderiv`. In this section, we prove
1080  this and related statements.
1081  -/
1082  
1083  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                         └──────────────────────┘
src                         └──────────────────────┘
typ                        └──────────────────────┘
doc                         └──────────────────────┘
1084  {E : Type*} [normed_group E] [normed_space 𝕜 E]
id                └──────────┘     └──────────┘
src               └──────────┘     └──────────┘
typ               └──────────┘     └──────────┘
doc               └──────────┘     └──────────┘
1085  {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
id                 └──────────┘      └──────────┘
src                └──────────┘      └──────────┘
typ                └──────────┘      └──────────┘
doc                └──────────┘      └──────────┘
1086  {f : E → E'} {s : set E} {x : E}
id                     └─┘
src                    └─┘
typ                    └─┘
1087  
1088  lemma unique_mdiff_within_at_iff_unique_diff_within_at :
1089    unique_mdiff_within_at (model_with_corners_self 𝕜 E) s x ↔ unique_diff_within_at 𝕜 s x :=
id     └────────────────────┘  └─────────────────────┘       └───────────────────┘   
src    └────────────────────┘  └─────────────────────┘           └───────────────────┘
typ    └────────────────────┘  └─────────────────────┘       └───────────────────┘   
doc    └────────────────────┘  └─────────────────────┘            └───────────────────┘
1090  by simp [unique_mdiff_within_at]
id            └────────────────────┘
src     └────┘└────────────────────┘└─
typ     └────┘└────────────────────┘└─
doc     └────┘└────────────────────┘└─
txt     └────┘                      └─
par     └────┘                      └─
pid                               
st     └──────────────────────────────
1091  
src  
typ  
doc  
txt  
par  
pid  
st   
1092  lemma unique_mdiff_on_iff_unique_diff_on :
1093    unique_mdiff_on (model_with_corners_self 𝕜 E) s ↔ unique_diff_on 𝕜 s :=
id     └─────────────┘  └─────────────────────┘      └────────────┘  
src    └─────────────┘  └─────────────────────┘         └────────────┘
typ    └─────────────┘  └─────────────────────┘      └────────────┘  
doc    └─────────────┘  └─────────────────────┘          └────────────┘
1094  by simp [unique_mdiff_on, unique_diff_on, unique_mdiff_within_at_iff_unique_diff_within_at]
id            └─────────────┘  └────────────┘  └──────────────────────────────────────────────┘
src     └────┘└─────────────┘└┘└────────────┘└┘└──────────────────────────────────────────────┘└─
typ     └────┘└─────────────┘└┘└────────────┘└┘└──────────────────────────────────────────────┘└─
doc     └────┘└─────────────┘└┘└────────────┘└┘                                                └─
txt     └────┘               └┘              └┘                                                └─
par     └────┘               └┘              └┘                                                └─
pid                        └┘              └┘                                                
st     └─────────────────────────────────────────────────────────────────────────────────────────
1095  
src  
typ  
doc  
txt  
par  
pid  
st   
1096  @[simp] lemma written_in_ext_chart_model_space :
doc    └──┘
1097    written_in_ext_chart_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') x f = f :=
id     └─────────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘     
src    └─────────────────────┘  └─────────────────────┘       └─────────────────────┘           
typ    └─────────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘     
doc    └─────────────────────┘  └─────────────────────┘       └─────────────────────┘
1098  by { ext y, simp [written_in_ext_chart_at] }
id                     └─────────────────────┘
src       └───┘  └────┘└─────────────────────┘└┘
typ       └───┘  └────┘└─────────────────────┘└┘
doc       └───┘  └────┘└─────────────────────┘└┘
txt       └───┘  └────┘                       └┘
par       └───┘  └────┘                       └┘
pid          └┘                             
st     └──────┘└───────────────────────────────┘└┘
1099  
1100  /-- For maps between vector spaces, mdifferentiable_within_at and fdifferentiable_within_at coincide -/
1101  theorem mdifferentiable_within_at_iff_differentiable_within_at :
1102    mdifferentiable_within_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x
id     └───────────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘    
src    └───────────────────────┘  └─────────────────────┘       └─────────────────────┘
typ    └───────────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘    
doc    └───────────────────────┘  └─────────────────────┘       └─────────────────────┘
1103    ↔ differentiable_within_at 𝕜 f s x :=
id      └──────────────────────┘    
src     └──────────────────────┘
typ     └──────────────────────┘    
doc      └──────────────────────┘
1104  begin
st   └─────
1105    simp [mdifferentiable_within_at],
id           └───────────────────────┘
src    └────┘└───────────────────────┘
typ    └────┘└───────────────────────┘
doc    └────┘└───────────────────────┘
txt    └────┘                         
par    └────┘                         
pid                                 
st   ─────────────────────────────────┘└─
1106    exact ⟨λH, H.2, λH, ⟨H.continuous_within_at, H⟩⟩
id                           └───────────────────┘
src    └────┘  └─┘ └──┘ └─┘  └───────────────────┘└┘ └─┘
typ    └────┘  └─┘ └──┘ └─┘  └───────────────────┘└┘ └─┘
doc    └────┘  └─┘ └──┘ └─┘                       └┘ └─┘
txt    └────┘  └─┘ └──┘ └─┘                       └┘ └─┘
par    └────┘  └─┘ └──┘ └─┘                       └┘ └─┘
pid           └─┘ └──┘ └─┘                       └┘ └┘
st   ──────────────────────────────────────────────────┘
1107  end
st   └─┘
1108  
1109  /-- For maps between vector spaces, mdifferentiable_at and differentiable_at coincide -/
1110  theorem mdifferentiable_at_iff_differentiable_at :
1111    mdifferentiable_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f x
id     └────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘   
src    └────────────────┘  └─────────────────────┘       └─────────────────────┘
typ    └────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘   
doc    └────────────────┘  └─────────────────────┘       └─────────────────────┘
1112    ↔ differentiable_at 𝕜 f x :=
id      └───────────────┘   
src     └───────────────┘
typ     └───────────────┘   
doc      └───────────────┘
1113  begin
st   └─────
1114    simp [mdifferentiable_at, differentiable_within_at_univ],
id           └────────────────┘  └───────────────────────────┘
src    └────┘└────────────────┘└┘└───────────────────────────┘
typ    └────┘└────────────────┘└┘└───────────────────────────┘
doc    └────┘└────────────────┘└┘                             
txt    └────┘                  └┘                             
par    └────┘                  └┘                             
pid                          └┘                             
st   ─────────────────────────────────────────────────────────┘└─
1115    exact ⟨λH, H.2, λH, ⟨H.continuous_at, H⟩⟩
id                           └────────────┘
src    └────┘  └─┘ └──┘ └─┘  └────────────┘└┘ └─┘
typ    └────┘  └─┘ └──┘ └─┘  └────────────┘└┘ └─┘
doc    └────┘  └─┘ └──┘ └─┘                └┘ └─┘
txt    └────┘  └─┘ └──┘ └─┘                └┘ └─┘
par    └────┘  └─┘ └──┘ └─┘                └┘ └─┘
pid           └─┘ └──┘ └─┘                └┘ └┘
st   ───────────────────────────────────────────┘
1116  end
st   └─┘
1117  
1118  /-- For maps between vector spaces, mdifferentiable_on and differentiable_on coincide -/
1119  theorem mdifferentiable_on_iff_differentiable_on :
1120    mdifferentiable_on (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s
id     └────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘   
src    └────────────────┘  └─────────────────────┘       └─────────────────────┘
typ    └────────────────┘  └─────────────────────┘     └─────────────────────┘  └┘   
doc    └────────────────┘  └─────────────────────┘       └─────────────────────┘
1121    ↔ differentiable_on 𝕜 f s :=
id      └───────────────┘   
src     └───────────────┘
typ     └───────────────┘   
doc      └───────────────┘
1122  by simp [mdifferentiable_on, differentiable_on, mdifferentiable_within_at_iff_differentiable_within_at]
id            └────────────────┘  └───────────────┘  └────────────────────────────────────────────────────┘
src     └────┘└────────────────┘└┘└───────────────┘└┘└────────────────────────────────────────────────────┘└─
typ     └────┘└────────────────┘└┘└───────────────┘└┘└────────────────────────────────────────────────────┘└─
doc     └────┘└────────────────┘└┘└───────────────┘└┘└────────────────────────────────────────────────────┘└─
txt     └────┘                  └┘                 └┘                                                      └─
par     └────┘                  └┘                 └┘                                                      └─
pid                           └┘                 └┘                                                      
st     └─────────────────────────────────────────────────────────────────────────────────────────────────────
1123  
src  
typ  
doc  
txt  
par  
pid  
st   
1124  /-- For maps between vector spaces, mdifferentiable and differentiable coincide -/
1125  theorem mdifferentiable_iff_differentiable :
1126    mdifferentiable (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f
id     └─────────────┘  └─────────────────────┘     └─────────────────────┘  └┘  
src    └─────────────┘  └─────────────────────┘       └─────────────────────┘
typ    └─────────────┘  └─────────────────────┘     └─────────────────────┘  └┘  
doc    └─────────────┘  └─────────────────────┘       └─────────────────────┘
1127    ↔ differentiable 𝕜 f :=
id      └────────────┘  
src     └────────────┘
typ     └────────────┘  
doc      └────────────┘
1128  by simp [mdifferentiable, differentiable, mdifferentiable_at_iff_differentiable_at]
id            └─────────────┘  └────────────┘  └──────────────────────────────────────┘
src     └────┘└─────────────┘└┘└────────────┘└┘└──────────────────────────────────────┘└─
typ     └────┘└─────────────┘└┘└────────────┘└┘└──────────────────────────────────────┘└─
doc     └────┘└─────────────┘└┘└────────────┘└┘└──────────────────────────────────────┘└─
txt     └────┘               └┘              └┘                                        └─
par     └────┘               └┘              └┘                                        └─
pid                        └┘              └┘                                        
st     └─────────────────────────────────────────────────────────────────────────────────
1129  
src  
typ  
doc  
txt  
par  
pid  
st   
1130  /-- For maps between vector spaces, mfderiv_within and fderiv_within coincide -/
1131  theorem mfderiv_within_eq_fderiv_within :
1132    mfderiv_within (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x
id     └────────────┘  └─────────────────────┘     └─────────────────────┘  └┘    
src    └────────────┘  └─────────────────────┘       └─────────────────────┘
typ    └────────────┘  └─────────────────────┘     └─────────────────────┘  └┘    
doc    └────────────┘  └─────────────────────┘       └─────────────────────┘
1133    = fderiv_within 𝕜 f s x :=
id      └───────────┘    
src     └───────────┘
typ     └───────────┘    
doc      └───────────┘
1134  begin
st   └─────
1135    by_cases h : mdifferentiable_within_at (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f s x,
id                  └───────────────────────┘                               └─────────────────────┘  └┘    
src    └───────┘ └─┘└───────────────────────┘                          └┘ └─────────────────────┘   └┘  
typ    └───────┘ └─┘└───────────────────────┘                         └┘ └─────────────────────┘└┘└┘
doc    └───────┘ └─┘└───────────────────────┘                          └┘ └─────────────────────┘   └┘  
txt    └───────┘ └─┘                                                   └┘                           └┘  
par    └───────┘ └─┘                                                   └┘                           └┘  
pid             └─┘                                                   └┘                           └┘  
st   ──────────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1136    { simp [mfderiv_within, h] },
id             └────────────┘  
src      └────┘└────────────┘└┘ └┘
typ      └────┘└────────────┘└┘└┘
doc      └────┘└────────────┘└┘ └┘
txt      └────┘              └┘ └┘
par      └────┘              └┘ └┘
pid                        └┘ 
st   ───┘└───────────────────────┘└┘
1137    { simp [mfderiv_within, h],
id             └────────────┘  
src      └────┘└────────────┘└┘ 
typ      └────┘└────────────┘└┘
doc      └────┘└────────────┘└┘ 
txt      └────┘              └┘ 
par      └────┘              └┘ 
pid                        └┘ 
st   ───────────────────────────┘└─
1138      rw [mdifferentiable_within_at_iff_differentiable_within_at,
id           └────────────────────────────────────────────────────┘
src      └──┘└────────────────────────────────────────────────────┘└─
typ      └──┘└────────────────────────────────────────────────────┘└─
doc      └──┘└────────────────────────────────────────────────────┘└─
txt      └──┘                                                      └─
par      └──┘                                                      └─
pid        └┘                                                      └─
st   ─────────────────────────────────────────────────────────────┘└─
1139          differentiable_within_at] at h,
id           └──────────────────────┘
src  ───────┘└──────────────────────┘└────┘
typ  ───────┘└──────────────────────┘└────┘
doc  ───────┘└──────────────────────┘└────┘
txt  ───────┘                        └────┘
par  ───────┘                        └────┘
pid  ───────┘                        └───┘
st   ───────────────────────────────┘└───┘└─
1140      change ¬(∃(f' : tangent_space (model_with_corners_self 𝕜 E) x →L[𝕜]
id                                                                   └─┘ 
src      └─────┘  └────┘                                       └┘ └─┘ 
typ      └─────┘  └────┘                                      └┘ └─┘ 
doc      └─────┘   └────┘                                       └┘ └─┘ 
txt      └─────┘   └────┘                                       └┘      
par      └─────┘   └────┘                                       └┘      
pid               └────┘                                       └┘      
st   ────────────────────────────────────────────────────────────────────────
1141                      tangent_space (model_with_corners_self 𝕜 E') (f x)),
id                       └───────────┘  └─────────────────────┘  └┘        
src  ───────────────────┘└───────────┘ └─────────────────────┘   └┘   └┘
typ  ───────────────────┘└───────────┘ └─────────────────────┘└┘└┘   └┘
doc  ───────────────────┘└───────────┘ └─────────────────────┘   └┘   └┘ 
txt  ───────────────────┘                                        └┘   └┘ 
par  ───────────────────┘                                        └┘   └┘ 
pid  ───────────────────┘                                        └┘   └┘ 
st   ─────────────────────────────────────────────────────────────────────────
1142              has_fderiv_within_at f f' s x) at h,
id               └──────────────────┘      
src  ───────────┘└──────────────────┘     └────┘
typ  ───────────┘└──────────────────┘  └────┘
doc  ───────────┘└──────────────────┘     └────┘
txt  ───────────┘                         └────┘
par  ───────────┘                         └────┘
pid  ───────────┘                         └──┘
st   ──────────────────────────────────────────────┘└─
1143      simp [fderiv_within, h],
id             └───────────┘  
src      └────┘└───────────┘└┘ 
typ      └────┘└───────────┘└┘
doc      └────┘└───────────┘└┘ 
txt      └────┘             └┘ 
par      └────┘             └┘ 
pid                       └┘ 
st   ──────────────────────────┘└─
1144      refl }
src      └───┘
typ      └───┘
doc      └───┘
txt      └───┘
par      └───┘
pid          
st   ────────┘└─
1145  end
st   ──┘
1146  
1147  /-- For maps between vector spaces, mfderiv and fderiv coincide -/
1148  theorem mfderiv_eq_fderiv :
1149    mfderiv (model_with_corners_self 𝕜 E) (model_with_corners_self 𝕜 E') f x = fderiv 𝕜 f x :=
id     └─────┘  └─────────────────────┘     └─────────────────────┘  └┘     └────┘   
src    └─────┘  └─────────────────────┘       └─────────────────────┘            └────┘
typ    └─────┘  └─────────────────────┘     └─────────────────────┘  └┘     └────┘   
doc    └─────┘  └─────────────────────┘       └─────────────────────┘             └────┘
1150  begin
st   └─────
1151    rw [← mfderiv_within_univ, ← fderiv_within_univ],
id           └─────────────────┘    └────────────────┘
src    └────┘└─────────────────┘└──┘└────────────────┘
typ    └────┘└─────────────────┘└──┘└────────────────┘
doc    └────┘                   └──┘                  
txt    └────┘                   └──┘                  
par    └────┘                   └──┘                  
pid      └──┘                   └──┘                  
st   ──────────────────────────┘└────────────────────┘└──
1152    exact mfderiv_within_eq_fderiv_within
id           └─────────────────────────────┘
src    └────┘└─────────────────────────────┘
typ    └────┘└─────────────────────────────┘
doc    └────┘└─────────────────────────────┘
txt    └────┘                               
par    └────┘                               
pid                                        
st   ───────────────────────────────────────┘
1153  end
st   └─┘
1154  
1155  end mfderiv_fderiv
1156  
1157  /-! ### Differentiable local homeomorphisms -/
1158  namespace local_homeomorph.mdifferentiable
1159  
1160  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                          └──────────────────────┘
src                         └──────────────────────┘
typ                         └──────────────────────┘
doc                         └──────────────────────┘
1161  {E : Type*} [normed_group E] [normed_space 𝕜 E]
id                └──────────┘     └──────────┘
src               └──────────┘     └──────────┘
typ               └──────────┘     └──────────┘
doc               └──────────┘     └──────────┘
1162  {H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
id                └───────────────┘         └────────────────┘
src               └───────────────┘         └────────────────┘
typ               └───────────────┘         └────────────────┘
doc               └───────────────┘         └────────────────┘
1163  {M : Type*} [topological_space M] [manifold H M]
id                └───────────────┘     └──────┘
src               └───────────────┘     └──────┘
typ               └───────────────┘     └──────┘
doc               └───────────────┘     └──────┘
1164  {E' : Type*} [normed_group E'] [normed_space 𝕜 E']
id                 └──────────┘      └──────────┘
src                └──────────┘      └──────────┘
typ                └──────────┘      └──────────┘
doc                └──────────┘      └──────────┘
1165  {H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
id                 └───────────────┘           └────────────────┘
src                └───────────────┘           └────────────────┘
typ                └───────────────┘           └────────────────┘
doc                └───────────────┘           └────────────────┘
1166  {M' : Type*} [topological_space M'] [manifold H' M']
id                 └───────────────┘      └──────┘
src                └───────────────┘      └──────┘
typ                └───────────────┘      └──────┘
doc                └───────────────┘      └──────┘
1167  {E'' : Type*} [normed_group E''] [normed_space 𝕜 E'']
id                  └──────────┘       └──────────┘
src                 └──────────┘       └──────────┘
typ                 └──────────┘       └──────────┘
doc                 └──────────┘       └──────────┘
1168  {H'' : Type*} [topological_space H''] {I'' : model_with_corners 𝕜 E'' H''}
id                  └───────────────┘             └────────────────┘
src                 └───────────────┘             └────────────────┘
typ                 └───────────────┘             └────────────────┘
doc                 └───────────────┘             └────────────────┘
1169  {M'' : Type*} [topological_space M''] [manifold H'' M'']
id                  └───────────────┘       └──────┘
src                 └───────────────┘       └──────┘
typ                 └───────────────┘       └──────┘
doc                 └───────────────┘       └──────┘
1170  {e : local_homeomorph M M'} (he : e.mdifferentiable I I')
id        └──────────────┘              └──────────────┘
src       └──────────────┘              └──────────────┘
typ       └──────────────┘              └──────────────┘
doc       └──────────────┘              └──────────────┘
1171  {e' : local_homeomorph M' M''}
id         └──────────────┘
src        └──────────────┘
typ        └──────────────┘
doc        └──────────────┘
1172  include he
1173  
1174  lemma symm : e.symm.mdifferentiable I' I :=
id                └───┘└──────────────┘ └┘ 
src                └───┘└──────────────┘
typ               └───┘└──────────────┘ └┘ 
doc                └───┘└──────────────┘
1175  ⟨he.2, he.1⟩
id    └┘   └┘
src          
typ   └┘   └┘
1176  
1177  lemma mdifferentiable_at_to_fun {x : M} (hx : x ∈ e.source) :
id                                                  └─────┘
src                                                    └─────┘
typ                                                 └─────┘
1178    mdifferentiable_at I I' e.to_fun x :=
id     └────────────────┘  └┘ └─────┘ 
src    └────────────────┘       └─────┘
typ    └────────────────┘  └┘ └─────┘ 
doc    └────────────────┘
1179  (he.1 x hx).mdifferentiable_at (mem_nhds_sets e.open_source hx)
id    └┘   └┘ └────────────────┘   └───────────┘ └──────────┘ └┘
src            └────────────────┘   └───────────┘  └──────────┘
typ   └┘   └┘ └────────────────┘   └───────────┘ └──────────┘ └┘
1180  
1181  lemma mdifferentiable_at_inv_fun {x : M'} (hx : x ∈ e.target) :
id                                         └┘          └─────┘
src                                                      └─────┘
typ                                        └┘          └─────┘
1182    mdifferentiable_at I' I e.inv_fun x :=
id     └────────────────┘ └┘  └──────┘ 
src    └────────────────┘       └──────┘
typ    └────────────────┘ └┘  └──────┘ 
doc    └────────────────┘
1183  (he.2 x hx).mdifferentiable_at (mem_nhds_sets e.open_target hx)
id    └┘   └┘ └────────────────┘   └───────────┘ └──────────┘ └┘
src            └────────────────┘   └───────────┘  └──────────┘
typ   └┘   └┘ └────────────────┘   └───────────┘ └──────────┘ └┘
1184  
1185  variables [smooth_manifold_with_corners I M] [smooth_manifold_with_corners I' M']
id              └──────────────────────────┘       └──────────────────────────┘
src             └──────────────────────────┘       └──────────────────────────┘
typ             └──────────────────────────┘       └──────────────────────────┘
doc             └──────────────────────────┘       └──────────────────────────┘
1186  [smooth_manifold_with_corners I'' M'']
id    └──────────────────────────┘
src   └──────────────────────────┘
typ   └──────────────────────────┘
doc   └──────────────────────────┘
1187  
1188  lemma inv_fun_to_fun_deriv {x : M} (hx : x ∈ e.source) :
id                                             └─────┘
src                                               └─────┘
typ                                            └─────┘
1189    (mfderiv I' I e.inv_fun (e.to_fun x)).comp (mfderiv I I' e.to_fun x) = continuous_linear_map.id :=
id      └─────┘ └┘  └──────┘  └─────┘   └──┘   └─────┘  └┘ └─────┘    └──────────────────────┘
src     └─────┘       └──────┘   └─────┘    └──┘   └─────┘       └─────┘     └──────────────────────┘
typ     └─────┘ └┘  └──────┘  └─────┘   └──┘   └─────┘  └┘ └─────┘    └──────────────────────┘
doc     └─────┘                             └──┘   └─────┘                    └──────────────────────┘
1190  begin
st   └─────
1191    have : (mfderiv I I (e.inv_fun ∘ e.to_fun) x) =
id                                                  
src    └─────┘                            └┘ └┘
typ    └─────┘                            └┘ └┘
doc    └─────┘                             └┘ └┘ 
txt    └─────┘                             └┘ └┘ 
par    └─────┘                             └┘ └┘ 
pid    └───┘└┘                             └┘ └┘ 
st   ──────────────────────────────────────────────────
1192           (mfderiv I' I e.inv_fun (e.to_fun x)).comp (mfderiv I I' e.to_fun x) :=
id                          └───────┘                     └─────┘  └┘ └──────┘ 
src  ────────┘           └───────┘          └──────┘ └─────┘   └──────┘ └────
typ  ────────┘           └───────┘          └──────┘ └─────┘└┘└──────┘└────
doc  ────────┘                              └──────┘ └─────┘            └────
txt  ────────┘                              └──────┘                    └────
par  ────────┘                              └──────┘                    └────
pid  ────────┘                              └──────┘                    └───
st   ─────────────────────────────────────────────────────────────────────────────────
1193      mfderiv_comp x (he.mdifferentiable_at_inv_fun (e.map_source hx)) (he.mdifferentiable_at_to_fun hx),
id       └──────────┘   └───────────────────────────┘  └──────────┘       └──────────────────────────┘ └┘
src  ───┘└──────────┘  └───────────────────────────┘ └──────────┘  └─┘ └──────────────────────────┘  
typ  ───┘└──────────┘ └───────────────────────────┘ └──────────┘  └─┘ └──────────────────────────┘└┘
doc  ───┘                                                          └─┘                               
txt  ───┘                                                          └─┘                               
par  ───┘                                                          └─┘                               
pid  ───┘                                                          └─┘                               
st   ─────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1194    rw ← this,
id          └──┘
src    └───┘
typ    └───┘└──┘
doc    └───┘
txt    └───┘
par    └───┘
pid      └─┘
st   ──────────┘└─
1195    have : mfderiv I I (_root_.id : M → M) x = continuous_linear_map.id := mfderiv_id I,
id            └─────┘     └───────┘            └──────────────────────┘    └────────┘ 
src    └─────┘└─────┘   └───────┘└─┘   └┘  └──────────────────────┘└──┘└────────┘
typ    └─────┘└─────┘  └───────┘└─┘  └┘ └──────────────────────┘└──┘└────────┘
doc    └─────┘└─────┘            └─┘   └┘  └──────────────────────┘└──┘          
txt    └─────┘                   └─┘   └┘                          └──┘          
par    └─────┘                   └─┘   └┘                          └──┘          
pid    └───┘└┘                   └─┘   └┘                          └──┘          
st   ────────────────────────────────────────────────────────────────────────────────────┘└─
1196    rw ← this,
id          └──┘
src    └───┘
typ    └───┘└──┘
doc    └───┘
txt    └───┘
par    └───┘
pid      └─┘
st   ──────────┘└─
1197    apply mfderiv_congr_of_mem_nhds,
id           └───────────────────────┘
src    └────┘└───────────────────────┘
typ    └────┘└───────────────────────┘
doc    └────┘
txt    └────┘
par    └────┘
pid         
st   ────────────────────────────────┘└─
1198    have : e.source ∈ 𝓝 x := mem_nhds_sets e.open_source hx,
id            └──────┘       └───────────┘ └───────────┘ └┘
src    └─────┘└──────┘ └──┘└───────────┘└───────────┘
typ    └─────┘└──────┘└──┘└───────────┘└───────────┘└┘
doc    └─────┘          └──┘                          
txt    └─────┘           └──┘                          
par    └─────┘           └──┘                          
pid    └───┘└┘           └──┘                          
st   ────────────────────────────────────────────────────────┘└─
1199    apply filter.mem_sets_of_superset this,
id           └─────────────────────────┘ └──┘
src    └────┘└─────────────────────────┘
typ    └────┘└─────────────────────────┘└──┘
doc    └────┘                           
txt    └────┘                           
par    └────┘                           
pid                                    
st   ───────────────────────────────────────┘└─
1200    assume p hp,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid    └─────────┘
st   ────────────┘└─
1201    simp [e.left_inv, hp]
id                       └┘
src    └────┘          └┘  └┘
typ    └────┘└────────┘└┘└┘└┘
doc    └────┘          └┘  └┘
txt    └────┘          └┘  └┘
par    └────┘          └┘  └┘
pid                  └┘  
st   ───────────────────────┘
1202  end
st   └─┘
1203  
1204  lemma to_fun_inv_fun_deriv {x : M'} (hx : x ∈ e.target) :
id                                   └┘          └─────┘
src                                                └─────┘
typ                                  └┘          └─────┘
1205    (mfderiv I I' e.to_fun (e.inv_fun x)).comp (mfderiv I' I e.inv_fun x) = continuous_linear_map.id :=
id      └─────┘  └┘ └─────┘  └──────┘   └──┘   └─────┘ └┘  └──────┘    └──────────────────────┘
src     └─────┘       └─────┘   └──────┘    └──┘   └─────┘       └──────┘     └──────────────────────┘
typ     └─────┘  └┘ └─────┘  └──────┘   └──┘   └─────┘ └┘  └──────┘    └──────────────────────┘
doc     └─────┘                             └──┘   └─────┘                     └──────────────────────┘
1206  he.symm.inv_fun_to_fun_deriv hx
id   └┘└───┘└───────────────────┘ └┘
src    └───┘└───────────────────┘
typ  └┘└───┘└───────────────────┘ └┘
1207  
1208  set_option class.instance_max_depth 60
doc             └──────────────────────┘
1209  
1210  /-- The derivative of a differentiable local homeomorphism, as a continuous linear equivalence
1211  between the tangent spaces at `x` and `e.to_fun x`. -/
1212  protected def mfderiv {x : M} (hx : x ∈ e.source) :
id                                        └─────┘
src                                          └─────┘
typ                                       └─────┘
1213    tangent_space I x ≃L[𝕜] tangent_space I' (e.to_fun x) :=
id     └───────────┘   └─┘ └───────────┘ └┘  └─────┘ 
src    └───────────┘     └─┘  └───────────┘      └─────┘
typ    └───────────┘   └─┘ └───────────┘ └┘  └─────┘ 
doc    └───────────┘     └─┘  └───────────┘
1214  { inv_fun := (mfderiv I' I e.inv_fun (e.to_fun x)).to_fun,
id                 └─────┘ └┘  └──────┘  └─────┘   └────┘
src                └─────┘       └──────┘   └─────┘    └────┘
typ                └─────┘ └┘  └──────┘  └─────┘   └────┘
doc                └─────┘
1215    continuous_to_fun := (mfderiv I I' e.to_fun x).cont,
id                           └─────┘  └┘ └─────┘  └──┘
src                          └─────┘       └─────┘   └──┘
typ                          └─────┘  └┘ └─────┘  └──┘
doc                          └─────┘
1216    continuous_inv_fun := (mfderiv I' I e.inv_fun (e.to_fun x)).cont,
id                            └─────┘ └┘  └──────┘  └─────┘   └──┘
src                           └─────┘       └──────┘   └─────┘    └──┘
typ                           └─────┘ └┘  └──────┘  └─────┘   └──┘
doc                           └─────┘
1217    left_inv := λy, begin
id                  
typ                 
st                     └─────
1218      have : (continuous_linear_map.id : tangent_space I x →L[𝕜] tangent_space I x) y = y := rfl,
id               └──────────────────────┘                     └─┘ └───────────┘           └─┘
src      └─────┘ └──────────────────────┘└─┘               └─┘ └───────────┘  └┘  └──┘└─┘
typ      └─────┘ └──────────────────────┘└─┘               └─┘└───────────┘└┘ └──┘└─┘
doc      └─────┘ └──────────────────────┘└─┘               └─┘ └───────────┘  └┘   └──┘
txt      └─────┘                         └─┘                                   └┘   └──┘
par      └─────┘                         └─┘                                   └┘   └──┘
pid      └───┘└┘                         └─┘                                   └┘   └──┘
st   ─────────────────────────────────────────────────────────────────────────────────────────────┘└─
1219      conv_rhs { rw [← this, ← he.inv_fun_to_fun_deriv hx] },
id                        └──┘    └─────────────────────┘ └┘
src      └─────────┘└────┘    └──┘└─────────────────────┘  └┘
typ      └─────────┘└────┘└──┘└──┘└─────────────────────┘└┘└┘
txt      └─────────┘└────┘    └──┘                         └┘
par      └─────────┘└────┘    └──┘                         └┘
pid              └──────┘    └──┘                         └─┘
st   ─────────────┘└─────────┘└────────────────────────────┘ └┘
1220      refl
src      └────
typ      └────
doc      └────
txt      └────
par      └────
pid          
st   ─────────
1221    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
1222    right_inv := λy, begin
id                   
typ                  
st                      └─────
1223      have : (continuous_linear_map.id : tangent_space I' (e.to_fun x) →L[𝕜] tangent_space I' (e.to_fun x)) y = y := rfl,
id               └──────────────────────┘                                      └───────────┘ └┘  └──────┘            └─┘
src      └─────┘ └──────────────────────┘└─┘                         └┘     └───────────┘   └──────┘ └─┘   └──┘└─┘
typ      └─────┘ └──────────────────────┘└─┘                         └┘    └───────────┘└┘ └──────┘└─┘  └──┘└─┘
doc      └─────┘ └──────────────────────┘└─┘                         └┘     └───────────┘            └─┘   └──┘
txt      └─────┘                         └─┘                         └┘                              └─┘   └──┘
par      └─────┘                         └─┘                         └┘                              └─┘   └──┘
pid      └───┘└┘                         └─┘                         └┘                              └─┘   └──┘
st   ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1224      conv_rhs { rw [← this, ← he.to_fun_inv_fun_deriv (e.map_source hx)] },
id                        └──┘    └─────────────────────┘  └──────────┘ └┘
src      └─────────┘└────┘    └──┘└─────────────────────┘ └──────────┘  └─┘
typ      └─────────┘└────┘└──┘└──┘└─────────────────────┘ └──────────┘└┘└─┘
txt      └─────────┘└────┘    └──┘                                      └─┘
par      └─────────┘└────┘    └──┘                                      └─┘
pid              └──────┘    └──┘                                      └──┘
st   ─────────────┘└─────────┘└───────────────────────────────────────────┘ └┘
1225      rw e.to_local_equiv.left_inv hx,
id          └───────────────────────┘ └┘
src      └─┘└───────────────────────┘
typ      └─┘└───────────────────────┘└┘
doc      └─┘                         
txt      └─┘                         
par      └─┘                         
pid                                 
st   ──────────────────────────────────┘└─
1226      refl
src      └────
typ      └────
doc      └────
txt      └────
par      └────
pid          
st   ─────────
1227    end,
src  ─┘
typ  ─┘
doc  ─┘
txt  ─┘
par  ─┘
pid  ─┘
st   ─┘└─┘
1228    .. mfderiv I I' e.to_fun x }
id        └─────┘  └┘ └─────┘ 
src       └─────┘       └─────┘
typ       └─────┘  └┘ └─────┘ 
doc       └─────┘
1229  
1230  set_option class.instance_max_depth 100
doc             └──────────────────────┘
1231  
1232  lemma range_mfderiv_eq_univ {x : M} (hx : x ∈ e.source) :
id                                              └─────┘
src                                                └─────┘
typ                                             └─────┘
1233    range (mfderiv I I' e.to_fun x) = univ :=
id     └───┘  └─────┘  └┘ └─────┘    └──┘
src    └───┘  └─────┘       └─────┘     └──┘
typ    └───┘  └─────┘  └┘ └─────┘    └──┘
doc    └───┘  └─────┘
1234  (he.mfderiv hx).to_linear_equiv.to_equiv.range_eq_univ
id    └┘└──────┘ └┘ └─────────────┘ └──────┘ └───────────┘
src     └──────┘    └─────────────┘ └──────┘ └───────────┘
typ   └┘└──────┘ └┘ └─────────────┘ └──────┘ └───────────┘
doc     └──────┘
1235  
1236  lemma trans (he': e'.mdifferentiable I' I'') : (e.trans e').mdifferentiable I I'' :=
id                     └┘└──────────────┘ └┘ └─┘     └────┘ └┘ └─────────────┘   └─┘
src                      └──────────────┘             └────┘    └─────────────┘
typ                    └┘└──────────────┘ └┘ └─┘     └────┘ └┘ └─────────────┘   └─┘
doc                      └──────────────┘             └────┘    └─────────────┘
1237  begin
st   └─────
1238    split,
src    └───┘
typ    └───┘
doc    └───┘
txt    └───┘
par    └───┘
st   ──────┘└─
1239    { assume x hx,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid      └─────────┘
st   ───┘└─────────┘└─
1240      simp [local_equiv.trans_source] at hx,
id             └──────────────────────┘
src      └────┘└──────────────────────┘└─────┘
typ      └────┘└──────────────────────┘└─────┘
doc      └────┘                        └─────┘
txt      └────┘                        └─────┘
par      └────┘                        └─────┘
pid                                  └───┘
st   ────────────────────────────────────────┘└─
1241      exact ((he'.mdifferentiable_at_to_fun hx.2).comp _
id               └───────────────────────────┘
src      └────┘  └───────────────────────────┘  └──────────
typ      └────┘  └───────────────────────────┘  └──────────
doc      └────┘                                 └──────────
txt      └────┘                                 └──────────
par      └────┘                                 └──────────
pid                                            └──────────
st   ───────────────────────────────────────────────────────
1242             (he.mdifferentiable_at_to_fun hx.1)).mdifferentiable_within_at },
id               └──────────────────────────┘ └┘
src  ──────────┘ └──────────────────────────┘  └─────────────────────────────┘
typ  ──────────┘ └──────────────────────────┘└┘└─────────────────────────────┘
doc  ──────────┘                               └─────────────────────────────┘
txt  ──────────┘                               └─────────────────────────────┘
par  ──────────┘                               └─────────────────────────────┘
pid  ──────────┘                               └───────────────────────────┘└┘
st   ─────────────────────────────────────────────────────────────────────────┘└┘
1243    { assume x hx,
src      └─────────┘
typ      └─────────┘
doc      └─────────┘
txt      └─────────┘
par      └─────────┘
pid      └─────────┘
st   ──────────────┘└─
1244      simp [local_equiv.trans_target] at hx,
id             └──────────────────────┘
src      └────┘└──────────────────────┘└─────┘
typ      └────┘└──────────────────────┘└─────┘
doc      └────┘                        └─────┘
txt      └────┘                        └─────┘
par      └────┘                        └─────┘
pid                                  └───┘
st   ────────────────────────────────────────┘└─
1245      exact ((he.mdifferentiable_at_inv_fun hx.2).comp _
id               └───────────────────────────┘
src      └────┘  └───────────────────────────┘  └──────────
typ      └────┘  └───────────────────────────┘  └──────────
doc      └────┘                                 └──────────
txt      └────┘                                 └──────────
par      └────┘                                 └──────────
pid                                            └──────────
st   ───────────────────────────────────────────────────────
1246             (he'.mdifferentiable_at_inv_fun hx.1)).mdifferentiable_within_at }
id               └────────────────────────────┘ └┘
src  ──────────┘ └────────────────────────────┘  └─────────────────────────────┘
typ  ──────────┘ └────────────────────────────┘└┘└─────────────────────────────┘
doc  ──────────┘                                 └─────────────────────────────┘
txt  ──────────┘                                 └─────────────────────────────┘
par  ──────────┘                                 └─────────────────────────────┘
pid  ──────────┘                                 └───────────────────────────┘└┘
st   ───────────────────────────────────────────────────────────────────────────┘└─
1247  end
st   ──┘
1248  
1249  end local_homeomorph.mdifferentiable
1250  
1251  /-! ### Unique derivative sets in manifolds -/
1252  section unique_mdiff
1253  
1254  variables {𝕜 : Type*} [nondiscrete_normed_field 𝕜]
id                         └──────────────────────┘
src                         └──────────────────────┘
typ                        └──────────────────────┘
doc                         └──────────────────────┘
1255  {E : Type u} [normed_group E] [normed_space 𝕜 E]
id                 └──────────┘     └──────────┘
src                └──────────┘     └──────────┘
typ                └──────────┘     └──────────┘
doc                └──────────┘     └──────────┘
1256  {H : Type*} [topological_space H] {I : model_with_corners 𝕜 E H}
id                └───────────────┘         └────────────────┘
src               └───────────────┘         └────────────────┘
typ               └───────────────┘         └────────────────┘
doc               └───────────────┘         └────────────────┘
1257  {M : Type*} [topological_space M] [manifold H M] [smooth_manifold_with_corners I M]
id                └───────────────┘     └──────┘       └──────────────────────────┘
src               └───────────────┘     └──────┘       └──────────────────────────┘
typ               └───────────────┘     └──────┘       └──────────────────────────┘
doc               └───────────────┘     └──────┘       └──────────────────────────┘
1258  {E' : Type u} [normed_group E'] [normed_space 𝕜 E']
id                  └──────────┘      └──────────┘
src                 └──────────┘      └──────────┘
typ                 └──────────┘      └──────────┘
doc                 └──────────┘      └──────────┘
1259  {H' : Type*} [topological_space H'] {I' : model_with_corners 𝕜 E' H'}
id                 └───────────────┘           └────────────────┘
src                └───────────────┘           └────────────────┘
typ                └───────────────┘           └────────────────┘
doc                └───────────────┘           └────────────────┘
1260  {M' : Type*} [topological_space M'] [manifold H' M']
id                 └───────────────┘      └──────┘
src                └───────────────┘      └──────┘
typ                └───────────────┘      └──────┘
doc                └───────────────┘      └──────┘
1261  {s : set M}
id        └─┘
src       └─┘
typ       └─┘
1262  
1263  /-- If a set has the unique differential property, then its image under a local
1264  diffeomorphism also has the unique differential property. -/
1265  lemma unique_mdiff_on.unique_mdiff_on_preimage [smooth_manifold_with_corners I' M']
id                                                   └──────────────────────────┘ └┘ └┘
src                                                  └──────────────────────────┘
typ                                                  └──────────────────────────┘ └┘ └┘
doc                                                  └──────────────────────────┘
1266    (hs : unique_mdiff_on I s) {e : local_homeomorph M M'} (he : e.mdifferentiable I I') :
id           └─────────────┘         └──────────────┘  └┘        └──────────────┘  └┘
src          └─────────────┘           └──────────────┘              └──────────────┘
typ          └─────────────┘         └──────────────┘  └┘        └──────────────┘  └┘
doc          └─────────────┘           └──────────────┘              └──────────────┘
1267    unique_mdiff_on I' (e.target ∩ e.inv_fun ⁻¹' s) :=
id     └─────────────┘ └┘  └─────┘  └──────┘ └─┘ 
src    └─────────────┘      └─────┘   └──────┘ └─┘
typ    └─────────────┘ └┘  └─────┘  └──────┘ └─┘ 
doc    └─────────────┘                          └─┘
1268  begin
st   └─────
1269    /- Start from a point `x` in the image, and let `z` be its preimage. Then the unique
st   ───────────────────────────────────────────────────────────────────────────────────────
1270    derivative property at `x` is expressed through `ext_chart_at I' x`, and the unique
st   ──────────────────────────────────────────────────────────────────────────────────────
1271    derivative property at `z` is expressed through `ext_chart_at I z`. We will argue that
st   ─────────────────────────────────────────────────────────────────────────────────────────
1272    the composition of these two charts with `e` is a local diffeomorphism in vector spaces,
st   ───────────────────────────────────────────────────────────────────────────────────────────
1273    and therefore preserves the unique differential property thanks to lemma
st   ───────────────────────────────────────────────────────────────────────────
1274    `has_fderiv_within_at.unique_diff_within_at`, saying that a differentiable function with onto
st   ────────────────────────────────────────────────────────────────────────────────────────────────
1275    derivative preserves the unique derivative property.-/
st   ─────────────────────────────────────────────────────────
1276    assume x hx,
src    └─────────┘
typ    └─────────┘
doc    └─────────┘
txt    └─────────┘
par    └─────────┘
pid    └─────────┘
st   ────────────┘└─
1277    let z := e.inv_fun x,
id              └───────┘ 
src    └───────┘└───────┘
typ    └───────┘└───────┘
doc    └───────┘         
txt    └───────┘         
par    └───────┘         
pid    └───┘└─┘         
st   ─────────────────────┘└─
1278    have z_source : z ∈ e.source, by simp [hx.1, local_equiv.map_target],
id                       └──────┘           └┘    └────────────────────┘
src    └──────────────┘ └──────┘     └────┘  └──┘└────────────────────┘
typ    └──────────────┘└──────┘     └────┘└┘└──┘└────────────────────┘
doc    └──────────────┘               └────┘  └──┘                      
txt    └──────────────┘               └────┘  └──┘                      
par    └──────────────┘               └────┘  └──┘                      
pid    └───────────┘└─┘                     └──┘                      
st   ─────────────────────────────┘                                        └─
1279    have zx : e.to_fun z = x, by simp [z, hx.1],
id               └──────┘                └┘
src    └────────┘└──────┘       └────┘ └┘  └─┘
typ    └────────┘└──────┘     └────┘└┘└┘└─┘
doc    └────────┘                └────┘ └┘  └─┘
txt    └────────┘                └────┘ └┘  └─┘
par    └────────┘                └────┘ └┘  └─┘
pid    └─────┘└─┘                     └┘  └─┘
st   ─────────────────────────┘                   └─
1280    let F := ext_chart_at I z,
id              └──────────┘  
src    └───────┘└──────────┘ 
typ    └───────┘└──────────┘
doc    └───────┘└──────────┘ 
txt    └───────┘             
par    └───────┘             
pid    └───┘└─┘             
st   ──────────────────────────┘└─
1281    -- the unique derivative property at `z` is expressed through its preferred chart, that we call `F`.
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────
1282    have B : unique_diff_within_at 𝕜
id              └───────────────────┘ 
src    └───────┘└───────────────────┘ 
typ    └───────┘└───────────────────┘
doc    └───────┘└───────────────────┘ 
txt    └───────┘                      
par    └───────┘                      
pid    └────┘└─┘                      
st   ───────────────────────────────────
1283      (F.inv_fun ⁻¹' (s ∩ (e.source ∩ e.to_fun ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) (F.to_fun z),
id        └───────┘ └─┘     └──────┘   └──────┘       └──────────┘ └┘               └──────┘   └──────┘ 
src  ───┘ └───────┘└─┘   └──────┘ └──────┘     └──────────┘   └──────────┘ └──────┘└┘ └──────┘ 
typ  ───┘ └───────┘└─┘  └──────┘ └──────┘     └──────────┘└┘└──────────┘ └──────┘└┘ └──────┘
doc  ───┘          └─┘                          └──────────┘   └──────────┘         └┘          
txt  ───┘                                                      └──────────┘         └┘          
par  ───┘                                                      └──────────┘         └┘          
pid  ───┘                                                      └──────────┘         └┘          
st   ───────────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1284    { have : unique_mdiff_within_at I s z := hs _ hx.2,
id              └────────────────────┘       └┘   └┘
src      └─────┘└────────────────────┘   └──┘  └─┘  └┘
typ      └─────┘└────────────────────┘└──┘└┘└─┘└┘└┘
doc      └─────┘└────────────────────┘   └──┘  └─┘  └┘
txt      └─────┘                         └──┘  └─┘  └┘
par      └─────┘                         └──┘  └─┘  └┘
pid      └───┘└┘                         └──┘  └─┘  └┘
st   ───┘└──────────────────────────────────────────────┘└─
1285      have S : e.source ∩ e.to_fun ⁻¹' ((ext_chart_at I' x).source) ∈ 𝓝 z,
id                └──────┘   └──────┘       └──────────┘ └┘              
src      └───────┘└──────┘ └──────┘     └──────────┘   └────────┘ 
typ      └───────┘└──────┘ └──────┘     └──────────┘└┘└────────┘ 
doc      └───────┘                      └──────────┘   └────────┘ 
txt      └───────┘                                     └────────┘  
par      └───────┘                                     └────────┘  
pid      └────┘└─┘                                     └────────┘  
st   ──────────────────────────────────────────────────────────────────────┘└─
1286      { apply mem_nhds_sets,
id               └───────────┘
src        └────┘└───────────┘
typ        └────┘└───────────┘
doc        └────┘
txt        └────┘
par        └────┘
pid             
st   ─────┘└─────────────────┘└─
1287        apply e.continuous_to_fun.preimage_open_of_open e.open_source (ext_chart_at_open_source I' x),
id               └───────────────────────────────────────┘ └───────────┘  └──────────────────────┘ └┘ 
src        └────┘└───────────────────────────────────────┘└───────────┘ └──────────────────────┘   
typ        └────┘└───────────────────────────────────────┘└───────────┘ └──────────────────────┘└┘
doc        └────┘                                                                                  
txt        └────┘                                                                                  
par        └────┘                                                                                  
pid                                                                                               
st   ──────────────────────────────────────────────────────────────────────────────────────────────────┘└─
1288        simp [z_source, zx] },
id               └──────┘  └┘
src        └────┘        └┘  └┘
typ        └────┘└──────┘└┘└┘└┘
doc        └────┘        └┘  └┘
txt        └────┘        └┘  └┘
par        └────┘        └┘  └┘
pid                    └┘  
st   ─────────────────────────┘└┘
1289      have := this.inter S,
id               └────────┘ 
src      └──────┘└────────┘
typ      └──────┘└────────┘
doc      └──────┘          
txt      └──────┘          
par      └──────┘          
pid      └───┘└─┘          
st   ───────────────────────┘└─
1290      rw [unique_mdiff_within_at_iff] at this,
id           
src      └──┘
typ      └──┘
doc      └──┘
txt      └──┘
par      └──┘
pid        └┘
st   ────────┘
1291      exact this },
st                  └┘
1292    -- denote by `G` the change of coordinate, i.e., the composition of the two extended charts and
1293    -- of `e`
1294    let G := F.symm ≫ e.to_local_equiv ≫ (ext_chart_at I' x),
id                                                           
typ                                                          
1295    -- `G` is differentiable
1296    have M : ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)).mdifferentiable I I',
id                                                   └┘ 
typ                                                  └┘ 
1297    { have A := mdifferentiable_of_mem_atlas I (chart_mem_atlas H z),
id                                                                  
typ                                                                 
1298      have B := mdifferentiable_of_mem_atlas I' (chart_mem_atlas H' x),
id                                                                  └┘ 
typ                                                                 └┘ 
1299      exact A.symm.trans (he.trans B) },
st                                       └┘
1300    have Mmem : (chart_at H z).to_fun z ∈ ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)).source,
id                                                                                └┘ 
typ                                                                               └┘ 
1301      by simp [local_equiv.trans_source, local_equiv.map_source, z_source, zx],
1302    have A : differentiable_within_at 𝕜 G.to_fun (range I.to_fun) (F.to_fun z),
id                                                                            
typ                                                                           
1303    { refine (M.mdifferentiable_at_to_fun Mmem).2.congr (λp hp, _) _;
id                                                           
typ                                                          
1304      simp [G, written_in_ext_chart_at, ext_chart_at, F] },
st                                                          └┘
1305    -- let `G'` be its derivative
1306    let G' := fderiv_within 𝕜 G.to_fun (range I.to_fun) (F.to_fun z),
id                                                                  
typ                                                                 
1307    have D₁ : has_fderiv_within_at G.to_fun G' (range I.to_fun) (F.to_fun z) :=
id                                                                           
typ                                                                          
1308      A.has_fderiv_within_at,
1309    have D₂ : has_fderiv_within_at G.to_fun G'
1310      (F.inv_fun ⁻¹' (s ∩ (e.source ∩ e.to_fun ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) (F.to_fun z),
id                                                                                                       
typ                                                                                                      
1311    { apply D₁.mono,
1312      refine subset.trans (inter_subset_right _ _) _,
1313      simp [F, ext_chart_at, local_equiv.trans_target] },
id             
typ            
st                                                        └┘
1314    -- The derivative `G'` is onto, as it is the derivative of a local diffeomorphism, the composition
1315    -- of the two charts and of `e`.
1316    have C₁ : range (G' : E → E') = univ,
id                              └┘
typ                             └┘
1317    { have : G' = mfderiv I I' ((chart_at H z).symm ≫ₕ e ≫ₕ (chart_at H' x)).to_fun ((chart_at H z).to_fun z),
id                                                                       └┘                                 
typ                                                                      └┘                                 
1318        by { rw (M.mdifferentiable_at_to_fun Mmem).mfderiv, refl },
st                                                                  └┘
1319      rw this,
1320      exact M.range_mfderiv_eq_univ Mmem },
st                                          └┘
1321    have C₂ : closure (range (G' : E → E')) = univ, by rw [C₁, closure_univ],
id                                       └┘
typ                                      └┘
st                                                                            
1322    -- key step: thanks to what we have proved about it, `G` preserves the unique derivative property
1323    have key : unique_diff_within_at 𝕜
id                                      
typ                                     
1324      (G.to_fun '' (F.inv_fun ⁻¹' (s ∩ (e.source ∩ e.to_fun ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target))
id                                                                                  
typ                                                                                 
1325      (G.to_fun (F.to_fun z)) := D₂.unique_diff_within_at B C₂,
id                           
typ                          
1326    have : G.to_fun (F.to_fun z) = (ext_chart_at I' x).to_fun x, by { dsimp [G, F], simp [hx.1] },
id                                                                              
typ                                                                             
st                                                                                                 └┘
1327    rw this at key,
1328    apply key.mono,
1329    show G.to_fun '' (F.inv_fun ⁻¹' (s ∩ (e.source ∩ e.to_fun ⁻¹' ((ext_chart_at I' x).source))) ∩ F.target) ⊆
1330      (ext_chart_at I' x).inv_fun ⁻¹' e.target ∩ (ext_chart_at I' x).inv_fun ⁻¹' (e.inv_fun ⁻¹' s) ∩
id                                                                                                
typ                                                                                               
1331        range (I'.to_fun),
1332    rw image_subset_iff,
1333    rintros p ⟨⟨hp₁, ⟨hp₂, hp₄⟩⟩, hp₃⟩,
1334    simp [G, local_equiv.map_source, hp₂, hp₁, mem_preimage.1 hp₄, -mem_range, mem_range_self],
id           
typ          
1335    exact mem_range_self _
1336  end
st   └─┘
1337  
1338  /-- If a set in a manifold has the unique derivative property, then its pullback by any extended
1339  chart, in the vector space, also has the unique derivative property. -/
1340  lemma unique_mdiff_on.unique_diff_on (hs : unique_mdiff_on I s) (x : M) :
id                                                                       
typ                                                                      
1341    unique_diff_on 𝕜 ((ext_chart_at I x).target ∩ ((ext_chart_at I x).inv_fun ⁻¹' s)) :=
id                                                                                
typ                                                                               
1342  begin
1343    -- this is just a reformulation of `unique_mdiff_on.unique_mdiff_on_preimage`, using as `e`
1344    -- the local chart at `x`.
1345    assume z hz,
1346    simp [ext_chart_at, local_equiv.trans_target, -mem_range] at hz,
1347    have : (chart_at H x).mdifferentiable I I := mdifferentiable_chart _ _,
id                       
typ                      
1348    have T := (hs.unique_mdiff_on_preimage this) (I.inv_fun z),
id                                                             
typ                                                            
1349    simp only [ext_chart_at, (hz.left).left, (hz.left).right, hz.right, local_equiv.trans_target,
1350      unique_mdiff_on, unique_mdiff_within_at, local_equiv.refl_trans, forall_prop_of_true,
1351      model_with_corners_target, mem_inter_eq, preimage_inter, mem_preimage, chart_at_model_space_eq,
1352      local_homeomorph.refl_local_equiv, and_self, model_with_corners_right_inv,
1353      local_equiv.trans_inv_fun] at ⊢ T,
1354    convert T using 1,
1355    rw @preimage_comp _ _ _ _ (chart_at H x).inv_fun,
id                                          
typ                                         
1356    -- it remains to show that `(a ∩ b) ∩ c` = `(b ∩ c) ∩ a`, which finish can do but very slowly
1357    ext p,
1358    split;
1359    { assume hp, simp at hp, simp [hp] }
st                                        └─
1360  end
st   ──┘
1361  
1362  /-- When considering functions between manifolds, this statement shows up often. It entails
1363  the unique differential of the pullback in extended charts of the set where the function can
1364  be read in the charts. -/
1365  lemma unique_mdiff_on.unique_diff_on_inter_preimage (hs : unique_mdiff_on I s) (x : M) (y : M')
id                                                                                             └┘
typ                                                                                            └┘
1366    {f : M → M'} (hf : continuous_on f s) :
id             └┘                       
typ            └┘                       
1367    unique_diff_on 𝕜 ((ext_chart_at I x).target
id                                      
typ                                     
1368      ∩ ((ext_chart_at I x).inv_fun ⁻¹' (s ∩ f⁻¹' (ext_chart_at I' y).source))) :=
id                                                                 
typ                                                                
1369  begin
1370    have : unique_mdiff_on I (s ∩ f ⁻¹' (ext_chart_at I' y).source),
id                                                        
typ                                                       
1371    { assume z hz,
1372      apply (hs z hz.1).inter',
id                 
typ                
1373      apply (hf z hz.1).preimage_mem_nhds_within,
id                 
typ                
1374      exact mem_nhds_sets (ext_chart_at_open_source I' y) hz.2 },
id                                                        
typ                                                       
st                                                                └┘
1375    exact this.unique_diff_on _
1376  end
st   └─┘
1377  
1378  variables {F : Type u} [normed_group F] [normed_space 𝕜 F]
id                           └──────────┘     └──────────┘
src                          └──────────┘     └──────────┘
typ                          └──────────┘     └──────────┘
doc                          └──────────┘     └──────────┘
1379  (Z : basic_smooth_bundle_core I M F)
id        └──────────────────────┘
src       └──────────────────────┘
typ       └──────────────────────┘
doc       └──────────────────────┘
1380  
1381  /-- In a smooth fiber bundle constructed from core, the preimage under the projection of a set with
1382  unique differential in the basis also has unique differential. -/
1383  lemma unique_mdiff_on.smooth_bundle_preimage (hs : unique_mdiff_on I s) :
id                                                      └─────────────┘  
src                                                     └─────────────┘
typ                                                     └─────────────┘  
doc                                                     └─────────────┘
1384    unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F))
id     └─────────────┘  └───┘  └─────────────────────┘  
src    └─────────────┘   └───┘  └─────────────────────┘
typ    └─────────────┘  └───┘  └─────────────────────┘  
doc    └─────────────┘   └───┘  └─────────────────────┘
1385    (Z.to_topological_fiber_bundle_core.proj ⁻¹' s) :=
id                                        └──┘ └─┘ 
src                                        └──┘ └─┘
typ                                       └──┘ └─┘ 
doc                                        └──┘ └─┘
1386  begin
1387    /- Using a chart (and the fact that unique differentiability is invariant under charts), we
1388    reduce the situation to the model space, where we can use the fact that products respect
1389    unique differentiability. -/
1390    assume p hp,
1391    replace hp : p.fst ∈ s, by simpa using hp,
id                          
typ                         
1392    let e₀ := chart_at H p.1,
id                        
typ                       
1393    let e := chart_at (H × F) p,
id                           
typ                          
1394    -- It suffices to prove unique differentiability in a chart
1395    suffices h : unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F))
id                                                                    
typ                                                                   
1396      (e.target ∩ e.inv_fun⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s)),
id                                                                             
typ                                                                            
1397    { have A : unique_mdiff_on (I.prod (model_with_corners_self 𝕜 F)) (e.symm.target ∩
id                                                                  
typ                                                                 
1398        e.symm.inv_fun ⁻¹' (e.target ∩ e.inv_fun⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s))),
id                                                                                                  
typ                                                                                                 
1399      { apply h.unique_mdiff_on_preimage,
1400        exact (mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)).symm,
1401        apply_instance },
st                        └┘
1402      have : p ∈ e.symm.target ∩
1403        e.symm.inv_fun ⁻¹' (e.target ∩ e.inv_fun⁻¹' (Z.to_topological_fiber_bundle_core.proj ⁻¹' s)),
id                                                                                                  
typ                                                                                                 
1404          by simp [e, hp],
1405      apply (A _ this).mono,
1406      assume q hq,
1407      simp [e, local_equiv.left_inv _ hq.1] at hq,
1408      simp [hq] },
st                 └┘
1409    -- rewrite the relevant set in the chart as a direct product
1410    have : (λ (p : E × F), (I.inv_fun p.1, p.snd)) ⁻¹' e.target ∩
1411           (λ (p : E × F), (I.inv_fun p.1, p.snd)) ⁻¹' (e.inv_fun ⁻¹' (prod.fst ⁻¹' s)) ∩
id                    
typ                   
1412           range (λ (p : H × F), (I.to_fun p.1, p.snd))
id                             
typ                            
1413      = set.prod (I.inv_fun ⁻¹' (e₀.target ∩ e₀.inv_fun⁻¹' s) ∩ range I.to_fun) univ,
id                                                            
typ                                                           
1414    { ext q,
1415      split;
1416      { assume hq,
1417        simp [-mem_range, mem_range_self, prod_range_univ_eq.symm] at hq,
1418        simp [-mem_range, mem_range_self, hq, prod_range_univ_eq.symm] } },
st                                                                        └──┘
1419    assume q hq,
1420    replace hq : q.1 ∈ (chart_at H p.1).target ∧ (chart_at H p.1).inv_fun q.1 ∈ s,
id                                                                                
typ                                                                               
1421      by simpa using hq,
1422    simp only [unique_mdiff_within_at, ext_chart_at, model_with_corners.prod, local_equiv.refl_trans,
1423               local_equiv.refl_to_fun, topological_fiber_bundle_core.proj, id.def, range_id,
1424               model_with_corners_self_local_equiv, local_equiv.refl_inv_fun, preimage_inter,
1425               chart_at_model_space_eq, local_homeomorph.refl_local_equiv, this],
1426    -- apply unique differentiability of products to conclude
1427    apply unique_diff_on.prod _ is_open_univ.unique_diff_on,
1428    { simp [-mem_range, mem_range_self, hq] },
st                                             └┘
1429    { assume x hx,
1430      have A : unique_mdiff_on I (e₀.target ∩ e₀.inv_fun⁻¹' s),
id                                                             
typ                                                            
1431      { apply hs.unique_mdiff_on_preimage,
1432        exact (mdifferentiable_of_mem_atlas _ (chart_mem_atlas _ _)),
1433        apply_instance },
st                        └┘
1434      simp [unique_mdiff_on, unique_mdiff_within_at, ext_chart_at] at A,
1435      have B := A (I.inv_fun x) hx.1.1 hx.1.2,
id                              
typ                             
1436      rwa [← preimage_inter, model_with_corners_right_inv _ hx.2] at B }
st                                                                        └─
1437  end
st   ──┘
1438  
1439  lemma unique_mdiff_on.tangent_bundle_proj_preimage (hs : unique_mdiff_on I s):
id                                                                              
typ                                                                             
1440    unique_mdiff_on I.tangent ((tangent_bundle.proj I M) ⁻¹' s) :=
id                                                             
typ                                                            
1441  hs.smooth_bundle_preimage _
1442  
1443  end unique_mdiff